Skip to content
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

src: return early if nextTickQueue is empty #10274

Merged
merged 1 commit into from
Dec 21, 2016

Conversation

trevnorris
Copy link
Contributor

@trevnorris trevnorris commented Dec 15, 2016

Checklist
  • make -j4 test (UNIX), or vcbuild test nosign (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Description of change

This brings the node::MakeCallback and node::AsyncWrap::MakeCallback
implementations into alignment in that they return early if the
nextTickQueue is empty after processing the MicrotaskQueue.

Include test to make sure early return happens. Test has text explaining
the conditions for the test to pass, since it relies on internal
mechanisms that aren't guaranteed in the future.

R=@bnoordhuis
R=@addaleax

CI: https://ci.nodejs.org/job/node-test-commit/6652/

@trevnorris trevnorris added c++ Issues and PRs that require attention from people who are familiar with C++. lts-watch-v4.x labels Dec 15, 2016
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lts-watch-v6.x labels Dec 15, 2016
Copy link
Member

@addaleax addaleax left a comment

Choose a reason for hiding this comment

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

LGTM with a question

* - setImmediate() uses node::MakeCallback() instead of
* node::AsyncWrap::MakeCallback(). Otherwise the test will always pass.
* Have not found a way to verify that node::MakeCallback() is used.
*/
Copy link
Member

Choose a reason for hiding this comment

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

Could these conditions be checked by adding a test for the reverse situation? I.e. making sure that if there are ticks pending, the _tickDomainCallback is actually executed?

Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like a good idea. @trevnorris?

Copy link
Member

Choose a reason for hiding this comment

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

@Fishrock123 In response to my suggestion @trevnorris added the second (nested) setImmediate call below (which seems sufficient to me)

@trevnorris
Copy link
Contributor Author

@addaleax Think the update to the test addresses what you wanted to see.

CI: https://ci.nodejs.org/job/node-test-commit/6672/

Copy link
Member

@addaleax addaleax left a comment

Choose a reason for hiding this comment

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

Yeah, that’s pretty much what I had in mind. Thanks, this still LGTM!


process.on('exit', () => {
assert.ok(cntr > 0, '_tickDomainCallback was never called');
});
Copy link
Member

Choose a reason for hiding this comment

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

If you think being stricter is okay, we could just wrap the fake _tickDomainCallback in common.mustCall(·, 2) (You can probably judge whether the number of calls is likely to change).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@addaleax Though on my machine it would be common.mustCall(., 3). Because we can't actually process the nextTickQueue when overriding _tickDomainCallback() we can only guarantee it will be called at least once. I don't feel that being any stricter than that is possible w/o making some shaky assumptions on how the internals work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Likewise, adding mustCall() to process.on('exit' is pointless since mustCall callbacks are checked during 'exit'.

Copy link
Member

Choose a reason for hiding this comment

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

Though on my machine it would be common.mustCall(., 3)

I think that settles it, thanks for checking!

require('domain');
setImmediate(() => setImmediate(() => {
allsGood = true;
process.nextTick(() => {});
Copy link
Contributor

Choose a reason for hiding this comment

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

These should probably also all be wrapped in common.mustCall()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can set mustCall() around the setImmediate()'s, but not here. Since by overriding _tickDomainCallback() we loose the ability to process the nextTickQueue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also wrapping _tickDomainCallback() with mustCall() likewise isn't necessary since cntr is being checked on 'exit'.

@trevnorris
Copy link
Contributor Author

@addaleax @Fishrock123 Issues have either been addressed by commit or comment.

CI: https://ci.nodejs.org/job/node-test-commit/6691/

This brings the node::MakeCallback and node::AsyncWrap::MakeCallback
implementations into alignment in that they return early if the
nextTickQueue is empty after processing the MicrotaskQueue.

Include test to make sure early return happens. Test has text explaining
the conditions for the test to pass, since it relies on internal
mechanisms that aren't guaranteed in the future.

PR-URL: nodejs#10274
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
@trevnorris trevnorris merged commit 8f8db14 into nodejs:master Dec 21, 2016
trevnorris added a commit that referenced this pull request Dec 21, 2016
This brings the node::MakeCallback and node::AsyncWrap::MakeCallback
implementations into alignment in that they return early if the
nextTickQueue is empty after processing the MicrotaskQueue.

Include test to make sure early return happens. Test has text explaining
the conditions for the test to pass, since it relies on internal
mechanisms that aren't guaranteed in the future.

PR-URL: #10274
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
@trevnorris
Copy link
Contributor Author

Landed on v7.x-staging. Not critical so feel free to backport to LTS whenever.

evanlucas pushed a commit that referenced this pull request Jan 3, 2017
This brings the node::MakeCallback and node::AsyncWrap::MakeCallback
implementations into alignment in that they return early if the
nextTickQueue is empty after processing the MicrotaskQueue.

Include test to make sure early return happens. Test has text explaining
the conditions for the test to pass, since it relies on internal
mechanisms that aren't guaranteed in the future.

PR-URL: #10274
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
MylesBorins pushed a commit that referenced this pull request May 15, 2017
This brings the node::MakeCallback and node::AsyncWrap::MakeCallback
implementations into alignment in that they return early if the
nextTickQueue is empty after processing the MicrotaskQueue.

Include test to make sure early return happens. Test has text explaining
the conditions for the test to pass, since it relies on internal
mechanisms that aren't guaranteed in the future.

PR-URL: #10274
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
@MylesBorins MylesBorins mentioned this pull request May 23, 2017
andrew749 pushed a commit to michielbaird/node that referenced this pull request Jul 19, 2017
This brings the node::MakeCallback and node::AsyncWrap::MakeCallback
implementations into alignment in that they return early if the
nextTickQueue is empty after processing the MicrotaskQueue.

Include test to make sure early return happens. Test has text explaining
the conditions for the test to pass, since it relies on internal
mechanisms that aren't guaranteed in the future.

PR-URL: nodejs/node#10274
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
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++.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants