race condition
/ RAYSS kun-DISH-un /
A race condition is a bug where the outcome depends on which of two things finishes first — and since you can't control the timing, the result changes from run to run. It works nine times out of ten, then fails for no visible reason, which makes it one of the most maddening bugs to pin down.
Picture two people sharing one bank account, each withdrawing $100 at the very same instant. Both check the balance ($150), both see 'enough', both withdraw — and now the account is overdrawn. Neither did anything wrong alone; the trouble is that they 'raced' to act on the same number before either finished.
These bugs hide whenever two pieces of work run at the same time and touch the same thing — two threads, two requests, two clicks. The fix is to make sure only one can act at a time, or to design so the order genuinely doesn't matter. They're hard precisely because they often vanish the moment you slow things down to look.
balance = read() # both threads read 150
if balance >= 100: # both see 'enough'
write(balance-100) # both write 50 — but 100 vanishedTwo threads interleave on the same balance; one withdrawal silently disappears.
Notoriously 'works on my machine' — they often only show up under real load, never in the calm of a debugger.