-
Notifications
You must be signed in to change notification settings - Fork 21
[MongoDB] Fix resume token handling when no events are received #251
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
🦋 Changeset detectedLatest commit: 23dd6be The changes in this PR will be included in the next version bump. This PR includes changesets to release 14 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Rentacookie
reviewed
Apr 30, 2025
Rentacookie
reviewed
Apr 30, 2025
Rentacookie
previously approved these changes
Apr 30, 2025
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.
This must have been challenging to debug 😬
Rentacookie
approved these changes
Apr 30, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Our current implementation used resume tokens received from change stream events to resume the stream after a restart.
However, if the source collections do not receive writes, we do not receive any actual events, and the token is never advanced. If the source cluster receives many other oplog events, resuming the stream can become very slow after a while, or time out completely. Once it starts timing out, we don't have a way to recover other than restarting replication from scratch. The timeout typically shows up as an error "connection 2 to 159.41.94.47:27017 timed out". The error can be simulated by reducing
socketTimeoutMS
significantly (say 50ms).MongoDB does however provide new resume tokens even when there are no events:
https://www.mongodb.com/docs/manual/changeStreams/#std-label-change-stream-resume-token
The MongoDB driver exposes these as
stream.resumeToken
. There are some implementation details on exactly when this is updated, but in general it is safe to use that whenstream.tryNext()
returned null.This will avoid the case of the resume token falling to far behind, at least in the case where the service is running. For self-hosted cases, when the service is stopped for a while (or when there were connection errors for a while), it is still possible to run into the timeout. This doesn't implement automatic recovery from the timeout yet (since it is difficult to know whether the timeout is permanent or can just be retried), but does improve the error message.