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 an overflow on retries on container name conflicts #4752
Conversation
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.
@mtrmac Does this needs a test ? or if not possible you can add NO NEW TESTS NEEDED
in commit
LGTM |
to reflect a bit better what this does. Should not change behavior. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
Because Go integers silently overflow, and 10 is multiple of 2, repeatedly multiplying by 2 eventually turns suffixDigitsModulo into all-bits-zero, triggering a division by zero. So, cap the suffix to a 9-digit one. That is very likely to be sufficient. (But don't actually limit the number of retries. We could do that as well, for extra robustness. OTOH that would be another bit of code that we don't test...) [NO NEW TESTS NEEDED] We could plausibly unit-test the loop just to see that it doesn't crash on 100 conflicts in a row, but that's an awfully specific test that would require moving the loop to a separate function with a closure parameter, a complex test that makes the code less readable for a very specific crash. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
I did that, with an attempt at a justification in the commit. I can very well see an argument that this should have a unit test anyway, say so if you want me to write one. |
LGTM |
Thanks! Tests passed now. |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: mtrmac, rhatdan The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
What this PR does / why we need it:
Original report #4679 , probably requires a deterministically-seeded RNG.
Because Go integers silently overflow, and 10 is multiple of 2, repeatedly multiplying by 2 eventually turns suffixDigitsModulo
into all-bits-zero, triggering a division by zero.
So, cap the suffix to a 9-digit one. That is very likely to be sufficient.
(But don't actually limit the number of retries. We could do that as well, for extra robustness. OTOH that would be another bit of code that we don't test...)
How to verify it
With a deterministic RNG, and 32-bit integers, about 30 repeated triggers of this code should trigger that overflow. I didn’t try.
Which issue(s) this PR fixes:
Fixes #4679
Special notes for your reviewer:
Does this PR introduce a user-facing change?