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

Allow workers to continue execution if onerror is handled #16606

Closed
wants to merge 0 commits into from

Conversation

kylecarbs
Copy link

Fixes #16424.

self.onerror = (event) => {
  // Stops the worker from exiting, just like the browser.
}

The way I did this is certainly janky, and probably should not be merged in current state.

I wasn't sure how to mark the event loop alive, since the current exception handler increments unhandled errors. Maybe onQuietUnhandledRejectionHandlerCaptureValue should be replaced so this code is less confusing? Open to thoughts.

WebWorker__dispatchError(globalObject, worker.cpp_worker, bun.String.createUTF8(array.slice()), error_instance);
const handled = WebWorker__dispatchError(globalObject, worker.cpp_worker, bun.String.createUTF8(array.slice()), error_instance);
if (handled) {
vm.unhandled_error_counter -= 1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this should be decremented

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seemed suspect to me as well. I'll look at making a new handler instead.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not actually certain how else to do this without incrementing/decrementing whether it was handled or not. If you have thoughts, please lmk.

@Jarred-Sumner
Copy link
Collaborator

Had one comment. This does need a test before we can merge it though.

@kylecarbs
Copy link
Author

@Jarred-Sumner force pushed and GitHub auto-closed by accident 🤦

New PR is here with a test added. In my testing the decrement is fine, but definitely a bit janky.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

onerror in a Worker does not prevent thread exit
2 participants