Skip to content

Commit

Permalink
cancellation of interpreter execution (#40238)
Browse files Browse the repository at this point in the history
* add AbortSignal to interpreter

* adding AbortSignal to visualize_loader

* adding AbortSignal to embeddables and dashboard

* passing AbortSignal to courier request handler

* Remove abort signal from dashboard and move to handler, and abort fetches when necessary

* Remove the rest of the references to abort signal in dashboard

* Revert changes to dashboard_app

* Remove code related to canceling visualize requests and only keep stuff for canceling interpreter

* Use createError
  • Loading branch information
ppisljar authored and lukasolson committed Jul 30, 2019
1 parent b7ae57b commit 3ccc9a9
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export type getInitialContextFunction = () => InitialContextObject;
export interface Handlers {
getInitialContext: getInitialContextFunction;
inspectorAdapters?: Adapters;
abortSignal?: AbortSignal;
}

type Context = object;
Expand Down
1 change: 0 additions & 1 deletion src/legacy/ui/public/vis/request_handlers/courier.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ const CourierRequestHandlerProvider = function () {
inspectorAdapters,
queryFilter
}) {

// Create a new search source that inherits the original search source
// but has the appropriate timeRange applied via a filter.
// This is a temporary solution until we properly pass down all required
Expand Down
1 change: 1 addition & 0 deletions src/plugins/data/common/expressions/create_error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ export const createError = (err: any) => ({
error: {
stack: process.env.NODE_ENV === 'production' ? undefined : err.stack,
message: typeof err === 'string' ? err : err.message,
name: (err && err.name) || 'Error',
},
});
10 changes: 9 additions & 1 deletion src/plugins/data/common/expressions/interpreter_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,16 @@ export function interpreterProvider(config: any) {
// if something failed, just return the failure
if (getType(newContext) === 'error') return newContext;

// if execution was aborted return error
if (handlers.abortSignal && handlers.abortSignal.aborted) {
return createError({
message: 'The expression was aborted.',
name: 'AbortError',
});
}

// Continue re-invoking chain until it's empty
return await invokeChain(chain, newContext);
return invokeChain(chain, newContext);
} catch (e) {
// Everything that throws from a function will hit this
// The interpreter should *never* fail. It should always return a `{type: error}` on failure
Expand Down

0 comments on commit 3ccc9a9

Please sign in to comment.