Skip to content

Conversation

@TimothyGu
Copy link
Member

The first two commits of this PR are identical to #14710. However, the last two commits fixed the GC problem pointed out by @bnoordhuis in #14710 (review), and makes Connection an AsyncWrap for async hooks support.

With

const sess = new inspector.Session();
sess.connect();
sess.post('Runtime.evaluate', {
  expression: 'Promise.resolve(3)',
  awaitPromise: true
}, (err, msg) => {
  console.log(msg);
});

and appropriate async hooks, whereas before this PR it looked like

PROMISE(4): trigger: 1 execution: 1
PROMISE(5): trigger: 4 execution: 1
PROMISE(6): trigger: 4 execution: 1
before:  5
{ result: { type: 'number', value: 3, description: '3' } }
  TickObject(7): trigger: 5 execution: 5
after:   5
before:  6
after:   6
before:  7
after:   7
destroy: 7

after it

INSPECTORJSBINDING(5): trigger: 1 execution: 1
PROMISE(6): trigger: 1 execution: 1
PROMISE(7): trigger: 6 execution: 1
PROMISE(8): trigger: 6 execution: 1
before:  7
  before:  5
{ result: { type: 'number', value: 3, description: '3' } }
    TickObject(9): trigger: 5 execution: 5
  after:   5
after:   7
before:  8
after:   8
before:  9
after:   9
destroy: 9

with proper instrumentation.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

inspector

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. labels Sep 27, 2017
@eugeneo
Copy link
Contributor

eugeneo commented Sep 27, 2017

Sorry, I am not familiar with the AsyncWrap.

One of the essential requirements for the inspector API is to be able to send messages (and receive responses) while V8 is suspended. Will AsyncWrap work in this scenario?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this still needs to be reset in the destructor? It doesn’t happen automatically when ~Persistent() is called, unfortunately…

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice spot! It does indeed lead to a memory leak.

@addaleax
Copy link
Member

One of the essential requirements for the inspector API is to be able to send messages (and receive responses) while V8 is suspended. Will AsyncWrap work in this scenario?

This only changes the code for the inspector JS bindings, so I don’t think that is an issue? The code in this PR calls into JS at the same times when there were calls into JS before.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can leave these out, they are indirectly included by node_internals anyway :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't look like that is the case, unfortunately.

@mscdex mscdex added the inspector Issues and PRs related to the V8 inspector protocol label Sep 27, 2017
@TimothyGu TimothyGu removed the lib / src Issues and PRs related to general changes in the lib or src directory. label Sep 27, 2017
- Group all relevant methods/states into a C++ class.
- Uses internal fields instead of the less efficient v8::External for
  storing the pointer to the C++ object.
- Use AsyncWrap to allow instrumenting callback states.

Refs: nodejs#13503
@TimothyGu
Copy link
Member Author

TimothyGu commented Sep 28, 2017

CI: https://ci.nodejs.org/job/node-test-pull-request/10311/

Failures unrelated.

Copy link
Contributor

@trevnorris trevnorris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two style nits and one question about a #define. Nothing critical.

Local<Function> callback)
: AsyncWrap(env, wrap, PROVIDER_INSPECTORJSBINDING),
delegate_(env, this),
callback_(env->isolate(), callback) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style nit: mind changing the spacing of the initialization list to match that of NodeInspectorClient()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this was the predominant style for initializers, and I also prefer this style a bit more.

There are other places in the file where the initializer list is in this style. I'd be happy to make this consistent in a separate PR if you insist, but I think this change should get in now separated from stylistic changes..

void SendMessageToFrontend(const v8_inspector::StringView& message)
override {
Isolate* isolate = env_->isolate();
v8::HandleScope handle_scope(isolate);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: no need for the v8::; already using v8::HandleScope.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. This part of the code was just being moved around, but I'll fix it before landing.

NODE_ASYNC_NON_CRYPTO_PROVIDER_TYPES(V) \
NODE_ASYNC_CRYPTO_PROVIDER_TYPES(V)
NODE_ASYNC_CRYPTO_PROVIDER_TYPES(V) \
NODE_ASYNC_INSPECTOR_PROVIDER_TYPES(V) \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this end with a \?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, yes it should. Thanks for noticing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh oops, didn't realize it already had a \. I'd say it's good practice to always have a trailing backslash to reduce future diffs, but will remove.

TimothyGu added a commit to TimothyGu/node that referenced this pull request Oct 3, 2017
PR-URL: nodejs#15643
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Eugene Ostroukhov <[email protected]>
Reviewed-By: Trevor Norris <[email protected]>
Reviewed-By: James M Snell <[email protected]>
TimothyGu added a commit to TimothyGu/node that referenced this pull request Oct 3, 2017
- Group all relevant methods/states into a C++ class.
- Uses internal fields instead of the less efficient v8::External for
  storing the pointer to the C++ object.
- Use AsyncWrap to allow instrumenting callback states.

PR-URL: nodejs#15643
Refs: nodejs#13503
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Eugene Ostroukhov <[email protected]>
Reviewed-By: Trevor Norris <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@TimothyGu
Copy link
Member Author

Landed in 7157819 and 2f8ddb2.

@TimothyGu TimothyGu closed this Oct 3, 2017
@TimothyGu TimothyGu deleted the inspector branch October 3, 2017 04:40
addaleax pushed a commit to addaleax/ayo that referenced this pull request Oct 4, 2017
PR-URL: nodejs/node#15643
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Eugene Ostroukhov <[email protected]>
Reviewed-By: Trevor Norris <[email protected]>
Reviewed-By: James M Snell <[email protected]>
addaleax pushed a commit to addaleax/ayo that referenced this pull request Oct 4, 2017
- Group all relevant methods/states into a C++ class.
- Uses internal fields instead of the less efficient v8::External for
  storing the pointer to the C++ object.
- Use AsyncWrap to allow instrumenting callback states.

PR-URL: nodejs/node#15643
Refs: nodejs/node#13503
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Eugene Ostroukhov <[email protected]>
Reviewed-By: Trevor Norris <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@MylesBorins
Copy link
Contributor

ping re: backport

TimothyGu added a commit to TimothyGu/node that referenced this pull request Oct 22, 2017
Backport-PR-URL: nodejs#16071
PR-URL: nodejs#15643
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Eugene Ostroukhov <[email protected]>
Reviewed-By: Trevor Norris <[email protected]>
Reviewed-By: James M Snell <[email protected]>
TimothyGu added a commit to TimothyGu/node that referenced this pull request Oct 22, 2017
- Group all relevant methods/states into a C++ class.
- Uses internal fields instead of the less efficient v8::External for
  storing the pointer to the C++ object.
- Use AsyncWrap to allow instrumenting callback states.

Backport-PR-URL: nodejs#16071
PR-URL: nodejs#15643
Refs: nodejs#13503
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Eugene Ostroukhov <[email protected]>
Reviewed-By: Trevor Norris <[email protected]>
Reviewed-By: James M Snell <[email protected]>
evanlucas pushed a commit that referenced this pull request Oct 23, 2017
Backport-PR-URL: #16071
PR-URL: #15643
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Eugene Ostroukhov <[email protected]>
Reviewed-By: Trevor Norris <[email protected]>
Reviewed-By: James M Snell <[email protected]>
evanlucas pushed a commit that referenced this pull request Oct 23, 2017
- Group all relevant methods/states into a C++ class.
- Uses internal fields instead of the less efficient v8::External for
  storing the pointer to the C++ object.
- Use AsyncWrap to allow instrumenting callback states.

Backport-PR-URL: #16071
PR-URL: #15643
Refs: #13503
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Eugene Ostroukhov <[email protected]>
Reviewed-By: Trevor Norris <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@MylesBorins
Copy link
Contributor

Should this be backported to v6.x-staging? If yes please follow the guide and raise a backport PR, if not let me know or add the dont-land-on label.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. inspector Issues and PRs related to the V8 inspector protocol

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants