Hacktoberfest / hacktoberfest-2020

Hacktoberfest - App to manage the annual open-source challenge, used for the 2019 & 2020 seasons.

Home Page:https://hacktoberfest.digitalocean.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.