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

Fix possibility to generate duplicate IDs in XADD #275

Merged
merged 1 commit into from Jun 29, 2022
Merged

Fix possibility to generate duplicate IDs in XADD #275

merged 1 commit into from Jun 29, 2022

Conversation

readams
Copy link
Contributor

@readams readams commented Jun 28, 2022

The existing code is attempting to avoid duplicate IDs by checking the
last ID in the queue. But if the queue is emptied and a new event
added fast enough, it's possible to end up with duplicate IDs.

This simply adds a global variable that ensures IDs are monotonically
increasing across all streams.

@alicebob
Copy link
Owner

Thanks for the PR. That sounds dodgy indeed.

I only had a quick look, but would it be possible to add the lastID to the streamKey somehow, and avoid the global? I'll have a proper look soonish, though.

@readams
Copy link
Contributor Author

readams commented Jun 28, 2022

I thought about that but I believe the intent is that the ids should be unique across all streams. But doing our that way is still far less wrong so it's a possibility. Also I didn't look at the tests which are now failing.

@readams
Copy link
Contributor Author

readams commented Jun 28, 2022

I updated to store the last ID in streamKey and also keeping the older check based on the last ID from the stream, which allows the tests to pass.

The existing code is attempting to avoid duplicate IDs by checking the
last ID in the queue. But if the queue is emptied and a new event
added fast enough, it's possible to end up with duplicate IDs.

This adds a variable to streamKey that keeps track of the last ID even
when the stream itself is empty, which likely solves most cases where
this could cause problems.
@readams
Copy link
Contributor Author

readams commented Jun 28, 2022

(fixed commit message)

@alicebob alicebob merged commit 6c2297e into alicebob:master Jun 29, 2022
@alicebob
Copy link
Owner

Thanks for the update. This looks OK to me. It might change the behavior of existing tests in the wild, but imo it's a valid fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants