-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Don't proxy entire abort function back to the main thread #14911
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
Conversation
4d6ed8b
to
f9b13cb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this needed? As we proxy exceptions to the main thread, wouldn't just throwing an exception as abort does do all we need?
The use case in #11345 specifically requires that onAbort is called. In many cases the Module object that that includes the |
@@ -445,9 +445,6 @@ LibraryManager.library = { | |||
// TODO: There are currently two abort() functions that get imported to asm module scope: the built-in runtime function abort(), | |||
// and this function _abort(). Remove one of these, importing two functions for the same purpose is wasteful. | |||
abort__sig: 'v', | |||
// Proxy synchronously, which will have the effect of halting the program | |||
// and killing all threads, including this one. | |||
abort__proxy: 'sync', | |||
abort: function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a comment here, maybe
// abort() must be proxied, but we avoid the normal method since
// the runtime may not be in a good enough state to support that.
// Instead, it is proxied using postMessage, see library_pthread.js.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its not that abort needs to be proxied its just the onAbort
callback. I will add a comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Is there an existing test for this?)
Yes, the test I added back in #14669 tests exactly this. It injects the onAbort
handler during preInit which means that handler will only exist on the main thread and therefore must be invoked there:
Lines 2356 to 2360 in 8cbca51
@node_pthreads | |
def test_pthread_abort(self): | |
self.set_setting('PROXY_TO_PTHREAD') | |
self.add_pre_run("Module.onAbort = function() { console.log('onAbort called'); }") | |
self.do_run_in_out_file_test('pthread/test_pthread_abort.c', assert_returncode=NON_ZERO) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good.
(Is there an existing test for this?) |
f9b13cb
to
66c5af5
Compare
It turns out proxying abort has several issues: 1. If we do stuff like proxing during the call to abort it can allocate stack and heap space which might not be possible by the time abort is called. 2. All the other calls to abort that don't go via the library function (calls to abort directly from JS) are not proxied meaning we get inconsisten proxying. Instead I use postMessage to send just the onAbort and do the rest of the abort in the local thread. The exception will end up triggering the worker.onerror so go entire application will still get torn down.
66c5af5
to
41da87d
Compare
It turns out proxying abort has several issues:
it can allocate stack and heap space which might not
be possible by the time abort is called.
function (calls to abort directly from JS) are not proxied
meaning we get inconsistent proxying.
Instead I use postMessage to send just the onAbort and do
the rest of the abort in the local thread.
The exception will end up triggering the worker.onerror so
go entire application will still get torn down.