OhMyBug

concurrency/state

Cleanup runs before its last user

rare15 sightingsfirst seen September 2026

What goes wrong

A step that discards shared state is ordered ahead of an operation that still reads or writes that state. The later operation finds the value gone, or its write puts the value back. The author relies on the order that holds on the path they tested, assuming nothing else touches the state after the discard.

Example

Sign-out clears the saved destination and then flips the session flag, and the screen still mounted reacts to that flip by saving the destination again.

Not to be confused with

Not a missed cleanup or a path with no cleanup at all, as in cleanup on one exit path only: the cleanup here runs, but it runs at the wrong point relative to a pending user of the same state.

Discovered by

Field notes · 8

Read all 8 stories

Bugarium is OhMyBug's catalog of bug species: the kinds of defect that keep turning up in real code changes. Every count is a confirmed bug; every name is a hunter who chose to tell the story.