-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
new internalNextTick cannot be wrapped by electron #19104
Comments
There should almost certainly be a better way of doing this than exposing it on process — although I don't have anything to suggest off the top of my head. There's also the new |
I don't know much about electron internals but would it be possible to just use init async hooks instead of the unreliable monkey-patching? You would be looking for type |
I'm not familiar with setUnrefTimeout, what is it for? |
Yep, it would. It's going to be used in the 10.x release for http timeouts and similar, but it uses the same Timeout object under the hood so it triggers the same async hook. |
@apapirovski The solution looked really promising, but sadly there's some weird interaction between installing an async_hook (even one with a single empty handler) crashing the rendering of pdf inside an iframe (no idea how it is related at all... might be because of the promise hooking?). Is it still a feasible option to expose the internal next tick in process? |
Actually yeah, it seems to be related to the promise hooking, as soon as I commented out enablePromiseHook() it doesn't break the pdf viewer anymore O_o |
There's no chance we'll expose |
Also, if async hooks are crashing something within electron, it seems like there are deeper issues that need to be resolved. Seems pretty serious if that's a whole feature that can't be used. But I have literally no electron knowledge so unfortunately I'm useless there... |
I agree, I'm just trying to fix a bug I found on electron. However (just in case) I think I found some possible cause worth looking into, in env.cc:
the line however my knowledge of that part of the node code is kind of limited. Is there any reason you may know why this might happen? |
Not sure. Totally possible there's a bug on our end or V8s. I'll ping some folks... |
@xaviergonz Yes. I actually brought this up with @gsathya – the V8 For that to work, Node first needs to set an embedder field of that I assume that in Electron, the Chrome parts creates a lot of contexts on its own (e.g. for iframes, and probably the PDF viewer too), where no Node The most obvious two ways to tackle this would be either letting electron call
Just curious, does that happen to be a tagged pointer value for V8 that translates to the internal |
AFAIK yes, it seems to fail inside iframes, which are actually devoid of node integration features (if that's what you mean)
I'm sorry, you really lost me there. What code would I need to add to check for that in this particular case? (I just got into all this node + electron + chromium internal mess like 24h ago while trying to fix a silly bug :D ) |
If what you mean is what's the value of promise->IsNullOrUndefined(), then it is false at crash time. |
@xaviergonz Sorry, I kinda got it in my head that you were openening this issue because you were part of the electron team? 😄 Anyway, I’m sorry, my reply was kind of written with a different reader background in mind. (I can go into more detail on everything if you’re curious, though.)
Yes, that’s exactly what I mean. It’s good to know that they are devoid of Node features, I assume that that’s intentional?
I think you could run If that works, I think an okay-ish fix for this bug would be performing basically that check programatically in |
No worries, I don't get paid for any of this :D
Yes, for security reasons, there are ways in electron to disable this isolation, but usually you don't want an iframe loading some random page and having access to the node context. With your tip I just changed the code to
and there's no more process crashing anymore, hurray! |
Makes me wonder though, is this fix going to be applied? If so, under node v8, v9 or both? |
It would be good to know what Electron does in these cases (i.e. whether a Node context is being assigned or not).
You’d probably want to use the constant name in place of 32, and
I would lean towards “yes”. The downside here is that async state information would get lost across Contexts, but that’s in no way worse than a hard crash. Feel free to open a PR. :)
All release lines that have these hooks could receive this patch, in general. It might be worth trying to check if there’s a performance impact, that’s the only thing that might influence the decision to land this on Node 8. |
Cool, I changed the number to the constant name and created a pull request. However I didn't run any performance tests, is that done by CI? |
No. 😄 @bmeurer might have some decent benchmarks, afaik he was looking a lot into PromiseHook performance lately. |
Regarding |
@addaleax I don't have any benchmarks for the |
Instead of having mostly duplicate code in form of internalNextTick, instead use the existing defaultAsyncTriggerIdScope with a slight modification which allows undefined triggerAsyncId to be passed in, which then just triggers the callback with the provided arguments. PR-URL: #19147 Refs: #19104 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Andreas Madsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
Instead of having mostly duplicate code in form of internalNextTick, instead use the existing defaultAsyncTriggerIdScope with a slight modification which allows undefined triggerAsyncId to be passed in, which then just triggers the callback with the provided arguments. PR-URL: nodejs#19147 Refs: nodejs#19104 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Andreas Madsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
PR-URL: #19134 Fixes: #19104 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
PR-URL: #19134 Fixes: #19104 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
Due to the change from using
process.nextTick
toconst { nextTick } = require('internal/process/next_tick');
electron cannot wrap that call anymore in order to use its internalprocess.activateUvLoop()
, which is used on renderer processes to process the event queue (as seen in https://github.com/electron/electron/blob/7ef69a5af595c9c0eef27bdf9446103776917aec/lib/common/init.js)This is related to issue electron/electron#12108
If this internal "nextTick" were to be exported in process as process._internalNextTick and any calls that used this nextTick were changed to use process._internalNextTick instead (there are only like 4 or 5 and only used for network/http stuff so far) then electron would be able once more to wrap these calls and get those working again.
I'm open to create a pull request, but only if it is likely to get accepted.
The text was updated successfully, but these errors were encountered: