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

async_hooks: cleanup emitBefore and emitAfter in timers and nextTick #14050

Closed
wants to merge 2 commits into from
Closed

async_hooks: cleanup emitBefore and emitAfter in timers and nextTick #14050

wants to merge 2 commits into from

Conversation

AndreasMadsen
Copy link
Member

@AndreasMadsen AndreasMadsen commented Jul 3, 2017

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

async_hooks, process, timers

async_hooks: use common emitBefore and emitAfter

  • Timers and nextTick have special emitBefore and emitAfter functions for
    performance reasons. But if the assert in async_hooks.emitBefore is
    removed there is no difference.

edit: the checks are already included in pushAsyncIds.

async_hooks: require parameter in emitBefore

  • Using asyncId as the default triggerAsyncId is wrong. The triggerAsyncId
    can actually never be the asyncId.

/cc @nodejs/async_hooks

@nodejs-github-bot nodejs-github-bot added async_hooks Issues and PRs related to the async hooks subsystem. process Issues and PRs related to the process subsystem. timers Issues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout. labels Jul 3, 2017
@AndreasMadsen
Copy link
Member Author

AndreasMadsen commented Jul 3, 2017

if (asyncId < 0 || triggerAsyncId < 0) {
fatalError('before(): asyncId or triggerAsyncId is less than zero ' +
`(asyncId: ${asyncId}, triggerAsyncId: ${triggerAsyncId})`);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This is to throw nicely. If the values make it to AsyncWrap::PushAsyncIds() then it will abort (i.e. always core dump).

Copy link
Member Author

@AndreasMadsen AndreasMadsen Jul 4, 2017

Choose a reason for hiding this comment

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

Yes. But does this matter. asyncId < 0 and triggerAsyncId < 0 is for sure not a common error. We can keep the check, but then the performance of nextTick and the timers won't be exactly the same.

Copy link
Contributor

Choose a reason for hiding this comment

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

emitBeforeS is a (undocumented) user API and is exported via require(). The general rule has been that it shouldn't be possible for the application to abort via any method imported via require() (this does not hold true for process.binding()). But removing this allows require('async_hooks').emitBefore(-1, -1) to cause a CHECK() failure.

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, that makes sense. I will readd the checks later today.

emitBefore(asyncId, triggerAsyncId);
else
pushAsyncIds(asyncId, triggerAsyncId);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

History lesson: This was introduced originally because of a crazy method to keep track of the id stack. Which was a lot faster than it is currently, but added an obscene amount of complexity. I hope to simplify that approach in the future and reintroduce it, but seems I overlooked these calls can be removed for the time being.

emitBefore(asyncId, triggerAsyncId);
else
pushAsyncIds(asyncId, triggerAsyncId);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Reason these were here is for the same reason explained in nextTick.

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.

I don't want the check in emitBeforeS() to be removed. Other than that LGTM.

@AndreasMadsen
Copy link
Member Author

Timers and nextTick have special emitBefore and emitAfter functions for
historic reasons. These function are not needed any more, thus the
public emitBefore and emitAfter function can be used.
Using asyncId as the default triggerAsyncId is wrong. The triggerAsyncId
can actually never be the asyncId.
@AndreasMadsen
Copy link
Member Author

I reverted the commits that removed the assert and squashed the commits so it isn't confusing. I also rewrote the commit message.

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

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.

Thanks for the changes and additional commit message comments. LGTM

@AndreasMadsen
Copy link
Member Author

landed in 4e27aa9 and 84f9261

addaleax pushed a commit that referenced this pull request Jul 11, 2017
Timers and nextTick have special emitBefore and emitAfter functions for
historic reasons. These function are not needed any more, thus the
public emitBefore and emitAfter function can be used.

PR-URL: #14050
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
addaleax pushed a commit that referenced this pull request Jul 11, 2017
Using asyncId as the default triggerAsyncId is wrong. The triggerAsyncId
can actually never be the asyncId.

PR-URL: #14050
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
@addaleax addaleax mentioned this pull request Jul 11, 2017
addaleax pushed a commit that referenced this pull request Jul 18, 2017
Timers and nextTick have special emitBefore and emitAfter functions for
historic reasons. These function are not needed any more, thus the
public emitBefore and emitAfter function can be used.

PR-URL: #14050
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
addaleax pushed a commit that referenced this pull request Jul 18, 2017
Using asyncId as the default triggerAsyncId is wrong. The triggerAsyncId
can actually never be the asyncId.

PR-URL: #14050
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Fishrock123 pushed a commit that referenced this pull request Jul 19, 2017
Timers and nextTick have special emitBefore and emitAfter functions for
historic reasons. These function are not needed any more, thus the
public emitBefore and emitAfter function can be used.

PR-URL: #14050
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Fishrock123 pushed a commit that referenced this pull request Jul 19, 2017
Using asyncId as the default triggerAsyncId is wrong. The triggerAsyncId
can actually never be the asyncId.

PR-URL: #14050
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
async_hooks Issues and PRs related to the async hooks subsystem. process Issues and PRs related to the process subsystem. timers Issues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants