Race condition in assigning coupons
johndbritton opened this issue · comments
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.