mutated × shared — the answer changes between runs

Pooled-Resource Heisenbug

A pooled connection carries un-reset state from a prior borrower, so your result depends on who held it before you.

01the recipe

In the wild

example.py
# SMELL: a pooled connection carries un-reset state from a prior user.
# (impure-functions x resource-leaks)
conn = pool.acquire()
# the previous borrower left a transaction open / a session var set
rows = conn.execute("SELECT * FROM report")   # sees the leftover state
pool.release(conn)                            # returned dirty, never reset
# whether you get clean or dirty results depends on who held conn before you.

# RIGHT: reset on borrow and return; never trust pooled state.
conn = pool.acquire()
try:
    conn.rollback()                # a known-clean starting state
    rows = conn.execute("SELECT * FROM report")
finally:
    conn.rollback(); pool.release(conn)
A connection returned to the pool without being reset leaks its session state to the next borrower. The result depends on which pooled object you draw and what ran on it before -- the textbook Heisenbug that vanishes when you add logging or run it alone.
// observed
leaked: results depend on the prior borrower's leftover state
right: connection reset on borrow/return -- deterministic every draw
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.