-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Fix early crash on abort if the argument is circular #8657
Conversation
src/postamble.js
Outdated
} | ||
return value; | ||
}; | ||
}; |
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.
maybe declare this inside of abort since its only used in there?
What kind of situation would trigger this exactly? can we create a test for it somehow?
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.
Putting it inside abort would be good.
It's triggered by process["on"]("unhandledRejection",abort)
in nodejs (browser seems to work fine as it doesn't have the event). You can probably test it by calling process.emit("unhandledRejection", [CircularObject])
manually, after which abort will throw an exception as shown in the original example.
As for writing a test, maybe we can call abort([CircularObject])
catch the exception in abort and make sure that it's either caused by https://github.com/emscripten-core/emscripten/blob/incoming/src/postamble.js#L422 or by https://github.com/emscripten-core/emscripten/blob/incoming/src/postamble.js#L431
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.
I suggest maybe we change that line to process["on"]("unhandledRejection",onUnhandledRejection)
which can do whatever it wants and then call abort with a string value.
Also we can/should probably just simplify abort to call ".toString()" on its argument. I'm not sure it makes sense for abort to accept complex objects that need JSON formatting.
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.
Also we can/should probably just simplify abort to call ".toString()" on its argument.
That might also make the cause less obvious, often when calling toString()
javascript will return [object Object]
.
If I remember correctly process["on"]("unhandledRejection",onUnhandledRejection)
will stop nodejs from showing that there was an unhandledRejection, which means that the only feedback you get (by default) would be from the module.
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.
People shouldn't be calling abort
with arbitrary JS objects. I think its reasonable to expect it to take a string or an integer. Anyway, I guess I'm ok with this change as is now.
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.
I'm not sure, but I think we caught unhandledRejection because otherwise node didn't show a proper error during async wasm compilation. It's possible it's no longer necessary.
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.
That's interesting, well to resolve the issue I see a few options:
1.put the unhandledRejection
catcher itself behind a flag
2. fix abort
to be compatible with an external unhandledRejection
(this PR)
3. remove the unhandledRejection
(might break something if it is actually used somewhere)
The last one would be the best option in my opinion, but only if we can confirm that it is safe to remove
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.
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.
Thanks, yes, let's see if we still need to have unhandledRejection code. If not, then it would be nice to not have to add code to support circularity etc. as discussed earlier.
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.
I've looked at the test and it still fails if you comment unhandledRejection
. I've changed abort to use exit
(and console.error) instead of throw, and now it does work without unhandledRejection
. I'll be running the full test suite to make sure it doesn't break something else. If everything seems reasonable I'll create another PR.
Moving the function inside abort seems to break the closure compiler build, |
Thanks @i404788 , I think this idea is good! I'd prefer not to increase code size by default, though - how about only doing this when |
@kripken That sounds like a good idea, I think it would be good to replace the JSON.stringify altogether in non- |
Thanks, I think this looks good, but need to merge in latest incoming to fix the CI errors. |
Where do we stand on this PR? Separate from the unhandled rejection issue, I think it's best to not handle the circular case, that is, not do |
I would agree, for this PR/issue removing JSON.stringify would suffice. |
This looks good, but those errors on sanity look weird. I re-rean the test suite and they still happen. Do you see them locally? |
I saw the test failure and looked into it for a bit. The CI seems to suggests there is inactivity for a long time which is the same when I run it locally, however I have no idea where it comes from. |
Results (
To be fair the tests run a lot faster on my machine compared to the CI so I wouldn't be surprised if there was a 10m timeout on the CI. I'll try merging to latest incoming |
Thanks! Looks good now on the tests. |
…#8657) * Remove JSON.stringify from abort
Previously passing an circular object to abort would cause an early crash without showing any relevant information.
This patch uses a modified version of the MDN Circular Replacer Example
Example: