Skip to content

Commit

Permalink
Fix the issue of sandbox context not getting garbage collected
Browse files Browse the repository at this point in the history
  • Loading branch information
vedkribhu committed Jan 30, 2024
1 parent 1aba274 commit 7c0c1a1
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions lib/runner/extensions/event.command.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,34 +171,39 @@ module.exports = {

const originalContextOnHandler = context.on;

Check failure on line 172 in lib/runner/extensions/event.command.js

View workflow job for this annotation

GitHub Actions / Lint

'originalContextOnHandler' is assigned a value but never used

// We are overriding the context.on method to ensure for executions
// that are skipped, we don't trigger any events.
context.on = function (eventName, handler) {
originalContextOnHandler.call(context, eventName, function () {
const cursor = arguments && arguments[0];

if (cursor && cursor.execution && isExecutionSkipped(cursor.execution)) { return; }

handler.apply(context, arguments);
});
};

// store the host in run object for future use and move on
run.host = context;

context.on('console', function () {
const cursor = arguments && arguments[0];

if (cursor && cursor.execution && isExecutionSkipped(cursor.execution)) { return; }

run.triggers.console(...arguments);
});

context.on('error', function () {
const cursor = arguments && arguments[0];

if (cursor && cursor.execution && isExecutionSkipped(cursor.execution)) { return; }

run.triggers.error(...arguments);
});

context.on('execution.error', function () {
const cursor = arguments && arguments[0];

if (cursor && cursor.execution && isExecutionSkipped(cursor.execution)) { return; }

run.triggers.exception(...arguments);
});

context.on('execution.assertion', function () {
const cursor = arguments && arguments[0];

if (cursor && cursor.execution && isExecutionSkipped(cursor.execution)) { return; }

run.triggers.assertion(...arguments);
});

Expand Down Expand Up @@ -480,6 +485,7 @@ module.exports = {
this.host.removeAllListeners(EXECUTION_RESPONSE_EVENT_BASE + executionId);
this.host.removeAllListeners(EXECUTION_COOKIES_EVENT_BASE + executionId);
this.host.removeAllListeners(EXECUTION_ERROR_EVENT_BASE + executionId);
this.host.removeAllListeners(EXECUTION_SKIP_REQUEST_EVENT_BASE + executionId);

// Handle async errors as well.
// If there was an error running the script itself, that takes precedence
Expand Down

0 comments on commit 7c0c1a1

Please sign in to comment.