Source: thenewstack.io

How to Deal with Race Conditions

Category: Database

“Race conditions” refers to bugs that occur due to the timing or order of execution of multiple operations. This is a fairly broad class of bugs that can present themselves in very different ways, depending on the problem space.

https://en.wikipedia.org/wiki/Time-of-check_to_time-of-use (TOCTOU) describes a type of race condition that occurs when the state of a resource changes between checking its state and using the result. TOCTOU is usually discussed in the context of filesystem operations, but variations are possible in many areas of the systems we build.

Variations of this specific “create if not exist” race condition have popped up several times recently in third-party code and even our own.

Related Articles