Skip to content

Commit

Permalink
Fix bug where AbortController was not polyfilled on the server.
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeelmers committed Dec 9, 2020
1 parent 8e258ec commit 1e086ee
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/plugins/expressions/common/execution/execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,23 @@ import { getByAlias } from '../util/get_by_alias';
import { ExecutionContract } from './execution_contract';
import { ExpressionExecutionParams } from '../service';

/**
* AbortController is not available in Node until v15, so we
* need to temporarily mock it for plugins using expressions
* on the server.
*
* TODO: Remove this once Kibana is upgraded to Node 15.
*/
const getNewAbortController = (): AbortController => {
try {
return new AbortController();
} catch (error) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const polyfill = require('abortcontroller-polyfill/dist/cjs-ponyfill');
return new polyfill.AbortController();
}
};

const createAbortErrorValue = () =>
createError({
message: 'The expression was aborted.',
Expand Down Expand Up @@ -87,7 +104,7 @@ export class Execution<
/**
* AbortController to cancel this Execution.
*/
private readonly abortController = new AbortController();
private readonly abortController = getNewAbortController();

/**
* Promise that rejects if/when abort controller sends "abort" signal.
Expand Down

0 comments on commit 1e086ee

Please sign in to comment.