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 an overflow on retries on container name conflicts #4752

Merged
merged 2 commits into from May 2, 2023

Conversation

mtrmac
Copy link
Collaborator

@mtrmac mtrmac commented Apr 22, 2023

What type of PR is this?

/kind bug
/kind cleanup
/kind deprecation
/kind design
/kind documentation
/kind failing-test
/kind feature
/kind flake
/kind other

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?

None

Copy link
Collaborator

@flouthoc flouthoc left a 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

@rhatdan
Copy link
Member

rhatdan commented Apr 22, 2023

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>
@mtrmac
Copy link
Collaborator Author

mtrmac commented Apr 24, 2023

you can add NO NEW TESTS NEEDED in commit

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.

@TomSweeneyRedHat
Copy link
Member

LGTM
Test seemed to be timing out pulling Alpine. I've restarted.

@mtrmac
Copy link
Collaborator Author

mtrmac commented May 2, 2023

Thanks! Tests passed now.

@TomSweeneyRedHat
Copy link
Member

Happy green test buttons. @rhatdan @flouthoc @nalind PTAL

@rhatdan
Copy link
Member

rhatdan commented May 2, 2023

/approve
/lgtm

@openshift-ci openshift-ci bot added the lgtm label May 2, 2023
@rhatdan rhatdan merged commit f353690 into containers:main May 2, 2023
31 of 32 checks passed
@openshift-ci
Copy link
Contributor

openshift-ci bot commented May 2, 2023

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved label May 2, 2023
@mtrmac mtrmac deleted the retry-overflow branch May 2, 2023 23:27
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Repeated failure to create a container can trigger a panic
4 participants