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

No panic on new request id #397

Merged
merged 4 commits into from
Dec 20, 2024
Merged

No panic on new request id #397

merged 4 commits into from
Dec 20, 2024

Conversation

dimkouv
Copy link
Contributor

@dimkouv dimkouv commented Dec 20, 2024

newRequestID() might panic in some very rare case scenarios. Add some handling to prevent the panic.

"atomicCounter", atomicCounter.Load(),
)
t := time.Now().UTC().UnixNano()
c := atomicCounter.Add(1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The end of the timestamp has the most entropy, it would be better to include the counter at the front.

Not sure this is strictly correct, but I'm thinking something like this

b := make([]byte, 8)
binary.BigEndian.PutInt64(b, t)
b[0]=byte(c%256)

Copy link

Metric dk/noPanicOnNewRequestID main
Coverage 76.7% 76.6%

@dimkouv dimkouv merged commit 95fc747 into main Dec 20, 2024
17 checks passed
@winder winder deleted the dk/noPanicOnNewRequestID branch December 20, 2024 17:57
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.

2 participants