OhMyBug

concurrency/state

Check-Then-Create Race

#7uncommon38 sightingsfirst seen August 2026

What goes wrong

Several requests each check 'does this already exist?' or 'is there room?' and all see yes, because none has yet reserved its place with a unique constraint, lock, or atomic counter. Each then creates its own record, and things meant to be mutually exclusive all exist — the classic check-then-insert race.

Example

Double-click on 'Place order': both requests run 'count orders where cart = X', both get 0, both insert, and the customer gets two orders.

Not to be confused with

No lock or database constraint ties the check to the creation; a lock taken only after the check is Check Not Repeated Under Lock, and a client that forgets its retry key is Retry Gets New Idempotency Key.

Discovered by

Field notes · 4