-
Notifications
You must be signed in to change notification settings - Fork 30k
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
inspector: introduce inspector.SyncSession #27110
Conversation
This patch introduces a synchronous inspector session that dispatches the message and returns the result synchronously to the user.
Is the main difference to regular sessions that the result is returned from |
@addaleax Yeah, that makes the invocations that intend to use the results synchronously looks less awkward. I'll still need to investigate if this make sense for most methods, though. It seems inevitable that this has to be an EventEmitter to send out messages/notifications that are not triggered by a particular I'll need to complete the docs before sending it out for review.. |
Isn't it enough to add a |
Chrome team considered the fact that all V8 inspector messages are processed synchronously an implementation detail and there was specific goal not to make it a part of the interface. Chrome already has some asynchronous inspector calls outside the V8 domains. Promisifying this interface would be the correct way but so far it had not been possible due to the inspector restrictions (event loop may be paused while the messages are being processed) I am concerned that this interface will be broken down the line, as JavaScript evolves or other domains are being added to the Node Inspector. |
@targos Note that in the implementation, the sync variant uses Function::Call instead of MakeCallback to avoid triggering any microtasks or tick callbacks, or emitting any async hooks before returning the result to the user (which seems counterintuitive for a synchronous session). It's easier to implement this on a per-session basis, because the onMessage callback that connects the C++ and the JS land is per-session. |
Does this apply to all commands? There are commands explicitly marked as async in the protocol configuration, so I assumed that commands that are not marked are synchronous. We could also throw errors for those commands in the synchronous session, when we end up having to implement those asynchronously.
Would changes like that affect existing commands, or would they be added to the protocol as new commands? I believe if the commands have to return the result asynchronously, they would not look the same as they are now. Take heap snapshots for instance, even if you dispatch If we end up having to return results of commands asynchronously in their own invocation, would it be possible to keep them separate from the synchronous ones, so a synchronous session still works for commands that don't have to be asynchronous? (from what I can tell from the templates, the async commands and the synchronous commands already have their code generated differently, it just happens that the async ones are also implemented synchronously in Node.js). |
Fwiw, |
Yes, all commands are async. I am not sure what you mean by "protocol configuration" - if that is inspector_protocol_config.json then it is not a spec but a code generator configuration file, telling the code generator to pass in the callback instead of expecting a synchronous return value. In some cases in Chrome we flipped that switch as a part of an optimization or a refactoring effort and that did not require any change on the frontends. Note that the protocol viewer does not differentiate "async" and "sync" calls. Also, I believe it will be hugely confusing if some messages would work through this API and some would not.
All messages are considered async, no message is supposed to be safe from becoming async... |
For context, this came out of the discussion in https://chromium-review.googlesource.com/c/v8/v8/+/1546559 If we can't rely on the premise that we are able to use the inspector synchronously (wether exposed as a public API or not, at least for the commands we need), then we cannot rely on inspector in |
@@ -1,7 +1,7 @@ | |||
'use strict'; |
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.
Should we add docs for this change ?
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 won't be writing docs until I confirm this feature actually makes sense..
(now I am leaning towards no)
What do you think about making this an internal feature only (for use in inspect an maybe tests)? |
If the synchronicity can be broken, then we can't really build features that depend on this, right? |
I am going to use this PR (switched to internal as mentioned in #27110 (comment)) for the basis of an inspector-protocol based version of private fields inspection (#27404) given the feedback we've got from V8. TL;DR: the suggestion was to build on top of the current synchronicity of the inspector implementation in |
I think a better plan for now is to publish this as an npm package instead of bringing it into core |
publish it on npm may not bring enough attention. |
@joyeecheung Is this something we wanted to revisit again or as mentioned in comments, this shouldn't be in the core but to be part of a npm package? |
@antsmartian yeah, I don’t think this should be in core at the moment. |
This patch introduces a synchronous inspector session that
dispatches the message and returns the result synchronously
to the user.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes