-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
Conversation
if (provider === 'TCPWRAP') | ||
initCalls.add(id); | ||
}, 2), | ||
destroy: common.mustCallAtLeast((id) => { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
3c9015b
to
1e90b3f
Compare
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
1e90b3f
to
a052d4a
Compare
}).enable(); | ||
|
||
const res1 = new async_hooks.AsyncResource('foobar'); | ||
res2 = new async_hooks.AsyncResource('foobar'); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I think we’re superseding this by #13369, so I’m closing. Thanks for the review, though. 😄 |
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 mayinadvertently 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 waspossible that
destroy
hooks were scheduled but cleared before thenext event loop iteration in which they would have been emitted.
Ref: #13286
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
async_wrap