-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Don't call _emscripten_futex_wake if not a function #8481
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
This can happen if the thread throws on initialisation. Trying to call a function that doesn't exist will throw, hiding the previously caught exception. Fixes emscripten-core#8446.
How does this hide the previous exception? Both should be logged, I'd think? I tend to think that we should not add code that tries to make things work if the thread failed to even initialize - then the entire state of the world is just bad, and nothing can be expected to work. There are any number of other possible problems in that case, I'd guess. |
So the code I modified is in a try-catch. The logic is basically:
If restarting threads (3.) throws, then the previously caught error never gets re-thrown (4.). The point of this isn't to try and keep things working, its to try and make sure that the error that gets bubbled up is the initial error, not Basically this is about making the thrown error the correct/original one. |
I see. Ok, makes sense to improve the error for developers, I agree. How about doing something like this, though?
Putting it behind ASSERTIONS ensures it doesn't add overhead in general, and I think it's clearer as an assert (rather than an if that just skips something). |
Yeah I guess I can do that. I just thought overhead didn't really matter since it only reaches this check if something goes fatally wrong. |
The overhead is minor, I agree, but I think it's also a matter of clarity - an assertion directly says what we expect to be true there. |
I guess, but you lose useful information like the stack trace. Instead you get the stack trace of the wrong exception. And in builds without ASSERTIONS defined the wrong error is still thrown. |
Whichever way you do it can you make you there is comment about why |
@@ -203,7 +203,9 @@ this.onmessage = function(e) { | |||
} else { | |||
Atomics.store(HEAPU32, (threadInfoStruct + 4 /*C_STRUCTS.pthread.threadExitCode*/ ) >> 2, (e instanceof {{{ makeAsmGlobalAccessInPthread('ExitStatus') }}}) ? e.status : -2 /*A custom entry specific to Emscripten denoting that the thread crashed.*/); |
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.
Good point about the wrong stack trace being shown.
How about this: At the top of this else
body, we know that this isn't an infinite loop etc., and then we want to do some changes like these Atomics and the futex stuff. How about if before the atomics, we check if we managed to set up the thread properly, that is, move your if to up here, and put it behind ASSERTIONS. So something like
#if ASSERTIONS
if (typeof({{{ makeAsmGlobalAccessInPthread('_emscripten_futex_wake') }}}) !== "function") {
err("could not set up thread properly");
throw e;
}
#endif
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.
Done.
Great, thanks! Sorry for the amount of time this took, but it's important to get it right. Odd errors on CI, but I'm sure they can't be because of this, merging. |
…pten-core#8481) Without this PR we'dt call _emscripten_futex_wake which is not set up, and fail there, hiding the real error.
…pten-core#8481) Without this PR we'dt call _emscripten_futex_wake which is not set up, and fail there, hiding the real error.
This can happen if the thread throws on initialisation. Trying to call a function that doesn't exist will throw, hiding the previously caught exception.
Fixes #8446.