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

bugfix: actually raise on too many code collisions #729

Merged
merged 1 commit into from
Aug 25, 2019
Merged

bugfix: actually raise on too many code collisions #729

merged 1 commit into from
Aug 25, 2019

Conversation

brianchhun
Copy link
Contributor

Creating codes for invitations and invitation requests should raise on
the 10th attempt.

The "too many hash collisions" exception is never raised because the 10th try never happens. Using the inclusive range operator, instead of the exclusive one, makes it work.

Aside: the code columns for these models are missing a unique index. Is it worth adding or are too few concurrent creates for invitations and invitation requests for that to matter?

@pushcx
Copy link
Member

pushcx commented Aug 24, 2019

OK, first off, how did you find this bug? If you hit it in production, either you run by far the busiest instance of the codebase or you should be buying more lottery tickets.

In any case, thank you for finding, reporting, and fixing this bug. It occurs to me that this code could remove this coupling entirely by having the (1..10) loop set the code and return unless Invitation.exists?(:code => self.code), moving the raise below the loop and throwing away the conditional wrapping it. Then "do this 10 times" is expressed only once and can't slip out of sync. Sound good?

@brianchhun
Copy link
Contributor Author

I actually just found this while casually browsing the code base looking for inspiration. I've updated the code as you've suggested and removed the ranges in favor of 10.times.

Creating codes for invitations and invitation requests should raise on
the 10th attempt.
@pushcx pushcx merged commit d7328d3 into lobsters:master Aug 25, 2019
@pushcx
Copy link
Member

pushcx commented Aug 25, 2019

Thanks for contributing this fix back after your reading, then. :)

pushcx pushed a commit that referenced this pull request Jan 7, 2022
Use inclusive range instead of exclusive, remove conditional.
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