Kelly Mears

Race Condition

A defect whose occurrence depends on the relative timing of concurrent operations.

Testing & Verification2 min read241 words13 out · 34 in
also calledRace

A race condition occurs when the correctness of a result depends on the order in which concurrent operations happen to complete. Races are the archetypal intermittent bug: they reproduce on slow machines and vanish on fast ones, or the reverse. They are also the classic Heisenbug, since a print statement or a breakpoint shifts the timing enough to close the window the fault needed, and the bug disappears exactly when someone looks at it.

The web platform generates a particular family of them. A build tool's dependency scan finishing mid-run triggers a page reload that aborts whatever was in flight — so a random file fails, never the same one twice, and never on a fast local machine that wins the race every time. A resize observer's first callback lands a frame or two after mount, too late to prevent a visible jump and early enough to fight a user who has already scrolled. A framework re-rendering a subtree that a browser mutated directly diffs against a stale model.

Concurrent processes race in the same way over shared resources: two test runs in one working copy destroying each other's temporary files, two workers deriving the same port, two agents editing one directory.

The general remedies are to remove the shared resource (separate working copies, unique filenames), to make the ordering explicit (wait on an observable condition, not a duration), or to make the operation idempotent so order stops mattering. See Idempotence.

See also11

Flaky Test

A test that passes and fails on identical input, and the most corrosive thing a suite can contain.

Testing & Verification30 connections

Multi-Agent Orchestration

Coordinating several model instances on one body of work, each with its own context.

Agents & Language Models11 connections

Git Worktree

An additional working directory attached to one repository, each on its own branch.

Version Control & Delivery15 connections

Determinism

The property that identical inputs produce identical outputs, and the foundation of caching and verification.

Systems & Tooling61 connections

Bundler

The tool that resolves an application's modules into the files a browser downloads.

Web Platform18 connections

Reproducible Case

The smallest set of steps that reliably produces a fault, and the unit of real debugging.

Method27 connections

Fan-Out and Fan-In

Splitting work across parallel workers and recombining their results.

Agents & Language Models11 connections

Ground Truth

The measurement that arbitrates, as opposed to the artifact that merely reports.

Method99 connections

Token Budget

The finite allowance of model usage a task may consume, and the design decisions it forces.

Agents & Language Models20 connections

Time-of-Check to Time-of-Use

A race where a program checks a condition and then acts on it, but the world changes in between, the root of classic file-permission exploits and of double-spending bugs in web applications.

Systems & Tooling12 connections

Futex

The Linux primitive that makes locks cheap by handling the uncontended case entirely in user space and asking the kernel for help only when a thread actually has to wait, the foundation under most thread libraries.

Systems & Tooling8 connections

Linked from34