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_wrap: remove erroneous destroy list clear() #13353

Closed
wants to merge 1 commit into from

Conversation

addaleax
Copy link
Member

Breaking this out from #13286, Trevor said he had a better fix for the other problem and I believe him. :) @nodejs/async_hooks

Remove a .clear() call on the list of destroy ids that may
inadvertently swallow destroy events.

The list is already cleared earlier in the DestroyIdsCb function,
so usually this was a no-op; but when the garbage collection or
its equivalent was active during a destroy hook itself, it was
possible that destroy hooks were scheduled but cleared before the
next event loop iteration in which they would have been emitted.

Ref: #13286

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_wrap

@nodejs-github-bot nodejs-github-bot added async_wrap c++ Issues and PRs that require attention from people who are familiar with C++. labels May 31, 2017
if (provider === 'TCPWRAP')
initCalls.add(id);
}, 2),
destroy: common.mustCallAtLeast((id) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

😀 that's a good use for mustCallAtLeast I feel validated.

Copy link
Member Author

Choose a reason for hiding this comment

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

@refack Yeah, I kind of like it. 👍 You might want to re-review though, I’ve updated the test file quite a bit after Trevor’s comments in #13286 (comment)

Remove a `.clear()` call on the list of destroy ids that may
inadvertently swallow `destroy` events.

The list is already cleared earlier in the `DestroyIdsCb` function,
so usually this was a no-op; but when the garbage collection or
its equivalent was active during a `destroy` hook itself, it was
possible that `destroy` hooks were scheduled but cleared before the
next event loop iteration in which they would have been emitted.

Ref: nodejs#13286
}).enable();

const res1 = new async_hooks.AsyncResource('foobar');
res2 = new async_hooks.AsyncResource('foobar');
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume this is just for scoping, but it made me think is there any difference in const / let vars, I donno GC related or something?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm? This test is independent of GC. res2 isn’t const because it needs to be accessed from inside the hook, yes.

res2 = new async_hooks.AsyncResource('foobar');
res1.emitDestroy();

process.on('exit', () => assert.strictEqual(destroyResCallCount, 2));
Copy link
Contributor

Choose a reason for hiding this comment

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

You can instead do:
const sentinel = common.mustCall(() =>{}, 2);
and call sentinel() after the if in line 20

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 know, I don’t think that would be clearer here though.

Copy link
Member

@AndreasMadsen AndreasMadsen left a comment

Choose a reason for hiding this comment

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

LGTM

@addaleax
Copy link
Member Author

addaleax commented Jun 1, 2017

I think we’re superseding this by #13369, so I’m closing. Thanks for the review, though. 😄

@addaleax addaleax closed this Jun 1, 2017
@addaleax addaleax deleted the async-hooks-13286-a branch June 1, 2017 20:53
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.

5 participants