mutated × shared — the answer changes between runs

TOCTOU Race (Check-Then-Act)

The gap between checking a resource and using it is a window another actor can slip through — so the bug only fires when the interleaving lines up.

01the recipe

In the wild

example.py
# SMELL: check and use are two steps; state can change between them.
# (race-conditions x improper-initialization)
import os
if not os.path.exists(path):      # time-of-check
    os.makedirs(path)             # time-of-use -- another thread or process
                                  # may have created it in the gap -> crash

# RIGHT: act atomically; let the operation own the check.
os.makedirs(path, exist_ok=True)  # no window between check and use
The window between the existence check and the create is something another actor can race into. It surfaces only when threads interleave just so -- the textbook 'can't reproduce it.'
// observed
race:  intermittent FileExistsError under concurrency
right: deterministic, no check-use gap
02weakness catalog

Mapped weaknesses (CWE)

On its own, this defect is catalogued by MITRE as one or more of these weaknesses. The exploitable vulnerability usually appears only when it chains or combines with another.