Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed uncaughtException event listener not being removed #1036

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
unreleased:
fixed bugs:
- Fixed `uncaughtException` event listener not being removed

5.1.1:
date: 2024-08-01
fixed bugs:
Expand Down
32 changes: 13 additions & 19 deletions lib/sandbox/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,31 +187,27 @@ module.exports = function (bridge, glob) {
timers.clearAll();
}

// remove listener of disconnection event
bridge.off(abortEventName);
bridge.off(responseEventName);
bridge.off(cookiesEventName);
bridge.off('uncaughtException', onError);

// fire extra execution error event
if (err) { onError(err); }

// @note delete response from the execution object to avoid dispatching
// the large response payload back due to performance reasons.
execution.response && (delete execution.response);
function complete () {
bridge.off(abortEventName);
bridge.off(responseEventName);
bridge.off(cookiesEventName);
bridge.off('uncaughtException', onError);

if (dnd !== true) {
const dispatchExecutionResult = () => {
bridge.dispatch(executionEventName, err || null, execution);
};
// @note delete response from the execution object to avoid dispatching
// the large response payload back due to performance reasons.
execution.response && (delete execution.response);
bridge.dispatch(executionEventName, err || null, execution);
}

if (dnd !== true) {
// if execution is skipped, we dispatch execution completion
// event immediately to avoid any further processing else we
// dispatch it in next tick to allow any other pending events
// to be dispatched.
skippedExecution ?
dispatchExecutionResult() :
timers.wrapped.setImmediate(dispatchExecutionResult);
skippedExecution ? complete() : timers.wrapped.setImmediate(complete);
}
});

Expand Down Expand Up @@ -246,9 +242,7 @@ module.exports = function (bridge, glob) {
// and one of them throws an error, this handler will be triggered
// for all of them. This is a limitation of uvm as there is no way
// to isolate the uncaught exception handling for each execution.
bridge.on('uncaughtException', (err) => {
onError(err);
});
bridge.on('uncaughtException', onError);

if (!options.resolvedPackages) {
disabledAPIs.push('require');
Expand Down
Loading