fix: stop NewSubscriptionID from colliding#172
Closed
GregTheGreek wants to merge 1 commit intomainfrom
Closed
Conversation
Replace time.Now().UnixNano() with a monotonic atomic counter. The clock-based scheme collides on coarse-resolution clocks (commonly macOS, where consecutive calls in a tight loop return the same nanosecond), which surfaced as a persistent TestSubscriptionID_UniqueIDs failure on local test runs. The counter keeps the existing "sessionID-msgType-identifier" string format and Unwrap semantics unchanged - the identifier segment was already treated as an opaque string by consumers. Co-Authored-By: Claude
|
Go Test coverage is 53.3 %\ ✨ ✨ ✨ |
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
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.
Might not matter unless doing local dev without docker.
Summary
`NewSubscriptionID` relies on `time.Now().UnixNano()` for uniqueness. On macOS and other coarse-resolution clocks, consecutive calls in a tight loop return the same timestamp, so two subscription IDs collide. This is visible as a persistent failure of `TestSubscriptionID_UniqueIDs` (`comm/subID_test.go:32`) on local runs and any CI image with a lower-resolution monotonic clock.
Swap the nanosecond timestamp for a process-local `atomic.Uint64` counter. Monotonic, lock-free, and immune to clock resolution.
Why not UUIDs?
The identifier segment is an opaque string to every consumer (`Unwrap` splits on `-` and returns `subIDParts[2]` as a string without parsing). A counter keeps the existing format, stays compact, and needs no new dep.
Test plan
Notes