Skip to content
This repository has been archived by the owner on Mar 29, 2022. It is now read-only.
This repository has been archived by the owner on Mar 29, 2022. It is now read-only.

Race condition in assigning coupons #415

Open
johndbritton opened this issue Nov 6, 2019 · 0 comments
Open

Race condition in assigning coupons #415

johndbritton opened this issue Nov 6, 2019 · 0 comments
Labels
bug-report Unverified user submitted bug that needs verification help-wanted Looking for help from open source contributors

Comments

@johndbritton
Copy link
Contributor

We assign coupons in memory: https://github.com/raise-dev/hacktoberfest/blob/b6e5099f0e1486e81612d2c2e29ef334c27f6e7c/app/services/coupon_service.rb#L8-L14

And rely on Rails optimistic locking to ensure that the same coupon is not assigned to multiple users.

There were a few cases where users reported having received coupons that were already used. Upon inspection, a small number of coupons had lock_version greater than 1 meaning they were assigned multiple times.

This must be some sort of race condition that occurs under high concurrency.

It's not impacting any more users for this year, but will need to be addressed.

@johndbritton johndbritton added bug-report Unverified user submitted bug that needs verification help-wanted Looking for help from open source contributors labels Nov 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug-report Unverified user submitted bug that needs verification help-wanted Looking for help from open source contributors
Projects
None yet
Development

No branches or pull requests

1 participant