Skip to content

async_hooks: fix default nextTick triggerAsyncId - #14026

Closed
AndreasMadsen wants to merge 4 commits into
nodejs:masterfrom
AndreasMadsen:async-hooks-resource-null
Closed

async_hooks: fix default nextTick triggerAsyncId#14026
AndreasMadsen wants to merge 4 commits into
nodejs:masterfrom
AndreasMadsen:async-hooks-resource-null

Conversation

@AndreasMadsen

@AndreasMadsenAndreasMadsen commented Jul 1, 2017

Copy link
Copy Markdown
Member
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)

async_hooks

In the case where triggerAsyncId is null it should default to the
current executionAsyncId. This worked but as a side-effect the resource
object was changed too.

This fix also makes the null check more strict. EmitInitS is not a
documented API, thus there is no reason to be flexible in its input.

/cc @nodejs/async_hooks

@nodejs-github-botnodejs-github-bot added async_hooks Issues and PRs related to the async hooks subsystem. process Issues and PRs related to the process subsystem. labels Jul 1, 2017
@AndreasMadsen

AndreasMadsen commented Jul 1, 2017

Copy link
Copy Markdown
MemberAuthor

In the case where triggerAsyncId is null it should default to the
current executionAsyncId. This worked but as a side-effect the resource
object was changed too.
This fix also makes the null check more strict. EmitInitS is not a
documented API, thus there is no reason to be flexible in its input.
@AndreasMadsen

Copy link
Copy Markdown
MemberAuthor

I think we should implement this for now. But long term I'm wondering if we should eliminate the polymorphism in nextTick by explitly using initTriggerId().

@refackrefack left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Makes sense.
Left just some silly nits (ooof I hate to be the nit guy)

// later
if (this._allowNoInit) {
const stub = { uid, type: 'Unknown' };
const stub = { uid, type: 'Unknown', handleIsObject: true };

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: maybe just isObject? (here and everywhere, obviusly)

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

I would much rather be explicit, so many things could be an object.

@@ -147,7 +152,7 @@ class ActivityCollector {
// events this makes sense for a few tests in which we enable some hooks

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: If you're already here, could you turn this comment to a proper paragraph (capitalization, some punctuation, etc)

Comment threadlib/internal/process/next_tick.js Outdated
}

const asyncId = ++async_uid_fields[kAsyncUidCntr];
if (triggerAsyncId === null) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: Since it's argument overload handling, could you move it up, probably just after the if (process._exiting) return

Comment threadtest/async-hooks/init-hooks.js Outdated
uid,
type,
triggerAsyncId,
// in some cases (Timeout) the handle is a function, thus the usual

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: (I don't really mind but) start the sentence with a capital I. Also (e.g. `Timeout`)

@@ -0,0 +1,37 @@
'use strict';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: style as in https://github.com/nodejs/node/blob/master/doc/guides/writing-tests.md#test-structure (and but the //Flags on the first line 🤷‍♂️

@AndreasMadsen

AndreasMadsen commented Jul 3, 2017

Copy link
Copy Markdown
MemberAuthor

@AndreasMadsen

Copy link
Copy Markdown
MemberAuthor

landed in 0fd4c73

addaleax pushed a commit that referenced this pull request Jul 11, 2017
In the case where triggerAsyncId is null it should default to the
current executionAsyncId. This worked but as a side-effect the resource
object was changed too.
This fix also makes the null check more strict. EmitInitS is not a
documented API, thus there is no reason to be flexible in its input.
Ref: #13548 (comment)
PR-URL: #14026
Reviewed-By: Refael Ackermann <refack@gmail.com>
@addaleaxaddaleax mentioned this pull request Jul 11, 2017
addaleax pushed a commit that referenced this pull request Jul 18, 2017
In the case where triggerAsyncId is null it should default to the
current executionAsyncId. This worked but as a side-effect the resource
object was changed too.
This fix also makes the null check more strict. EmitInitS is not a
documented API, thus there is no reason to be flexible in its input.
Ref: #13548 (comment)
PR-URL: #14026
Reviewed-By: Refael Ackermann <refack@gmail.com>
Fishrock123 pushed a commit that referenced this pull request Jul 19, 2017
In the case where triggerAsyncId is null it should default to the
current executionAsyncId. This worked but as a side-effect the resource
object was changed too.
This fix also makes the null check more strict. EmitInitS is not a
documented API, thus there is no reason to be flexible in its input.
Ref: #13548 (comment)
PR-URL: #14026
Reviewed-By: Refael Ackermann <refack@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

async_hooksIssues and PRs related to the async hooks subsystem.processIssues and PRs related to the process subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@AndreasMadsen@refack@nodejs-github-bot