-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
fix(NODE-6010): Avoid triple-emitting close events #4031
Conversation
Hey @vkarpov15 - is there a specific bug you're trying to fix here or a specific issue this is addressing? It seems like you're only touching cursor behavior in this PR, but the reproduction uses change streams so I'm curious about the actual bug reported. I haven't been able to reproduce this behavior when testing locally. How are you restarting the cluster when testing?
Our cursor stream is a Nodejs stream, which emits an error on destroy(): https://nodejs.org/api/stream.html#writabledestroyerror |
is there a specific bug you're trying to fix here or a specific issue this is addressing? Node.js readable stream docs say that "the It seems like you're only touching cursor behavior in this PR, but the reproduction uses change streams so I'm curious about the actual bug reported. the root cause of the issue seems to be that abstract cursor calls I haven't been able to reproduce this behavior when testing locally. How are you restarting the cluster when testing? I used
Then killed the whole replica set with Ctrl+C, waited a bit, and restarted the replica set using the same command. Below is the output.
|
Hi @vkarpov15, apologies for the delay in response. Thanks for reporting this bug. I've reproduced the results you reported and have run your patch against our CI. While your patch does fix the immediate issue you reported, it does lead to a number of other test failures as we have certain functionality that depends on how our change streams emit close events. |
Description
If you kill and then restart the underlying replica set in the following script, you'll see that the
close
event is emitted 3 times:First time because abstract cursor
next()
cleans up the cursor:node-mongodb-native/src/cursor/abstract_cursor.ts
Lines 737 to 743 in 31f1eed
node-mongodb-native/src/cursor/abstract_cursor.ts
Line 846 in 31f1eed
2nd time because
ReadableCursorStream
callsdestroy()
:node-mongodb-native/src/cursor/abstract_cursor.ts
Line 943 in 31f1eed
close()
on the already closed cursor:node-mongodb-native/src/cursor/abstract_cursor.ts
Line 895 in 31f1eed
3rd time because
destroy
triggers an 'error' event for reasons that I haven't quite been able to figure outThis PR makes it so that only 1 'close' event is emitted, and it looks like all it does is prevent an extra unnecessary
close()
call?What is changing?
Is there new documentation needed for these changes?
What is the motivation for this change?
Release Highlight
Fill in title or leave empty for no highlight
Double check the following
npm run check:lint
scripttype(NODE-xxxx)[!]: description
feat(NODE-1234)!: rewriting everything in coffeescript