Join our Newsletter — 33% off our NHI Course
Home› Glossary› Cyber Security› Data Race
Cyber Security

Data Race

← Back to Glossary
By NHI Mgmt Group Updated November 18, 2026 Domain: Cyber Security

A data race is a bug where two or more threads access the same memory location at the same time, and at least one access is a write, without proper synchronisation. It can produce non-deterministic results because the program's behaviour depends on timing, scheduling and visibility between threads.

What a data race actually is

A data race is not just “two threads touching the same variable.” The bug exists when concurrent accesses overlap without the synchronisation needed to make ordering, exclusivity and visibility reliable. That distinction matters because the program may appear to work in testing and still fail unpredictably under different timing, core counts or compiler optimisations.

In practice, a data race turns a shared memory location into a source of nondeterminism. A write can be observed partially, late, out of order or not at all from another thread’s point of view, depending on the language memory model and the platform’s execution behaviour. That makes the defect especially hard to reproduce from a single run.

Why data races are dangerous

Data races can corrupt state silently rather than trigger an obvious crash. A counter may lose increments, a pointer or object field may be read before it is fully initialised, and a guard condition may be evaluated using stale values. Because the failure depends on timing, the same code path can succeed thousands of times before failing once in production.

The danger is broader than one bad variable. Once shared state becomes inconsistent, the defect can cascade into authorization mistakes, broken invariants, corrupted caches, incorrect retries or corrupted security decisions. Concurrency bugs are often most damaging when they sit behind code that everyone assumes is “simple” or “already thread-safe.”

How teams find and confirm the problem

Finding a data race usually requires more than ordinary unit testing. Teams use thread sanitizers and focused stress testing to expose access patterns that look harmless in source code but break under real scheduling. Sanitisers Guide explains how ThreadSanitizer and related tools fit into this workflow, including CI gating and fuzzing.

Confirmation is not only about seeing a failure once. Practitioners typically look for a reproducible interleaving, verify that the same memory is accessed concurrently, and then check whether the relevant lock, atomic operation or memory-ordering rule is missing. That is why the diagnosis often involves both code review and runtime instrumentation.

How to prevent and reduce exposure

Prevention starts with making ownership of shared state explicit. Use locks, atomics or other language-level synchronisation primitives consistently, and avoid ad hoc sharing patterns that depend on “it usually works.” If the program relies on a specific ordering between threads, that ordering should be encoded in the implementation rather than assumed by convention.

Where a race cannot be removed immediately, reduce the blast radius by limiting shared mutable state, narrowing concurrency around critical sections and adding tests that exercise high-contention paths. For security-sensitive code, treat race conditions as correctness failures that can become trust failures when state governs permissions, session handling or input validation.

Risk and Threat Considerations

Data races matter because they can turn a deterministic control path into a timing-dependent one. In security-relevant code, that can create inconsistent checks, stale reads or state corruption that an attacker may be able to trigger by increasing load or shaping request timing.

Failure mechanism: concurrent reads and writes occur without enforced ordering, so one thread acts on memory that another thread has not fully or consistently published.

Impact: the defect can cause privilege decisions, counters, caches or state transitions to diverge from intended behaviour, producing security exposure as well as functional failure.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

CIS Controls v8, NIST SP 800-53 Rev 5, OWASP ASVS and OWASP SAMM set the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
CIS Controls v8CIS-16 — Application Software SecurityData races are a software correctness flaw that secure coding and testing must catch.
Recommendation — Use secure coding review and concurrency testing to detect race-prone logic before release.
NIST SP 800-53 Rev 5SI-10 — Information Input ValidationRace-prone state handling can undermine assumptions behind validated inputs and downstream checks.
Recommendation — Validate state transitions and protect shared state so checks cannot be bypassed by timing.
OWASP ASVSV15 — Secure Coding and ArchitectureASVS covers secure design practices that include avoiding concurrency flaws in application logic.
Recommendation — Design shared-state handling so concurrent execution cannot violate intended program behaviour.
OWASP SAMMImplementation — ImplementationSAMM addresses building secure coding practices and defect prevention into the development lifecycle.
Recommendation — Embed concurrency testing and code review into implementation practices to catch race defects early.

Practitioner Guidance

What to watch for: shared mutable state is the main warning sign, especially when code mixes callbacks, worker pools, background tasks or lock-free structures. If a bug appears only under load, in CI, or on a different architecture, suspect a race before assuming randomness in the test environment.

Practitioner note: the safest fix is usually to make the access pattern obvious, not clever. If reviewers cannot easily explain who owns the data, when it is written, and what guarantees readers rely on, the code is already too fragile for concurrent execution.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Reviewed and updated by the NHIMG editorial team on November 18, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org