Skip to content

Prevents repeated panics from 14 poisoned locks after a caught panic - #3486

Merged
HakanSeven12 merged 2 commits into
HakanSeven12:mainfrom
travisjhughes:poisoned-lock-sites
Nov 23, 2026
Merged

HakanSeven12 merged 2 commits into
HakanSeven12:mainfrom
travisjhughes:poisoned-lock-sites

Conversation

@travisjhughes

Copy link
Copy Markdown
Contributor

Change summary

A Mutex that was locked when a thread panicked stays poisoned. .lock().unwrap() then panics at each later lock, so one caught panic becomes a panic at each later use. Most of the code base already recovers the data with .lock().unwrap_or_else(|e| e.into_inner()) (#3148 did this for the font locks). 14 sites in code for each platform did not:

File Sites The lock
src/modules/draw/modify/lengthen.rs 9 The defaults of LENGTHEN (mode and last values)
src/app/control/http_bridge.rs 3 The document id that the HTTP bridge remembers
src/schema_validation.rs 1 The cache of compiled JSON schemas
src/app/extraction_catalog.rs 1 The table of attribute keys of the data extraction wizard

This change makes them use the same recovery.

One of them has a path to a poisoned lock in the code today. validate_shape compiles a schema with .expect("application-owned schema must compile") while it holds the cache lock. If one schema does not compile, that panic poisons the cache, and each later validation of each other schema panics with "schema cache poisoned". The map is not changed before the panic, so its data stays good.

For the other three locks, the code that holds the lock only reads or writes plain values, so a panic there is not probable. The change makes them follow the rule of the code base.

What specifically changed

Two commits: the fix, then its tests.

  • The four files of the table: .lock().unwrap() and .lock().expect(..) become .lock().unwrap_or_else(|e| e.into_inner()). No other change.
  • Tests (3 new):
    • src/modules/draw/modify/lengthen.rs: a test poisons the lock of the defaults and then goes through each of the 9 sites. An existing test reads the lock with the same recovery now, because the tests run in parallel.
    • src/schema_validation.rs: a schema that does not compile panics; a validation with a good schema after that gives its usual results.
    • src/app/control/http_bridge.rs: harvest records the document id through a poisoned cache.

Why

  • Stops a panic in a command from ending the session #3454 keeps the session open after a panic in a message handler. A session that continues must not fail again at each use of a lock that the first failure poisoned.
  • The data behind each of these locks is plain (numbers, an id, a map that is changed in one step), so it is valid after a panic. Recovery is safe here.

Testing

On main 120199c0b.

  • The tests fail without the fix. With .unwrap() put back in the production code of the three files, all 3 new tests fail.
  • Each LENGTHEN site by hand: with .unwrap() put back at one site at a time, the LENGTHEN test fails for each of the 9 sites.
  • Before and after (cargo test --workspace --locked --no-fail-fast, cargo check --workspace --all-targets, clippy, the wasm32 check, rustfmt on the changed files, the golden file): 7,735 passed and 0 failed before; 7,737 passed and 1 failed after. The 3 new tests pass. The one failure is picklocked_off_makes_locked_layer_objects_unselectable, which is not stable on main (Test picklocked_off_makes_locked_layer_objects_unselectable fails at random when tests run in parallel #3468; Prevents random failures of the PICKLOCKED test when tests run in parallel #3485 repairs it) and is not from this change. Warnings, the wasm32 check, clippy, rustfmt and the golden file are the same.
  • Fault injection with cargo mutants on the diff: 13 mutants, 6 caught, 3 timeouts, 2 not viable, 2 missed. The timeouts are in the HTTP bridge, where a bridge test waits for an answer that the mutant never gives. The 2 missed mutants replace the result of leaked (extraction_catalog.rs); the run used only the tests of the four changed modules, and the tests of annotation_data catch that mutant (2 of them fail with it by hand).

Not covered

  • Two sites of the HTTP bridge and the site of the extraction catalog have no test of their own. The two bridge sites are in the request handler, which needs a live connection; the lock of the catalog is a static inside its function, so a test cannot poison it. The change there is the same one line.
  • The input code (src/input/: SpaceMouse and trackpad, 17 sites). Each part compiles on one platform only. A separate change.
  • The web build (src/app/control/mod.rs, src/scene/text/web_font.rs, 8 sites). The web build stops on a panic, so a poisoned lock cannot occur there.
  • The panic of a schema that does not compile. validate_shape still panics for that schema. Only the later validations are repaired.

Impact to Contributors

For a lock whose data stays valid after a panic, use .lock().unwrap_or_else(|e| e.into_inner()), not .lock().unwrap().

Co-Authored-By: Claude

A Mutex that was locked at a panic stays poisoned, and .lock().unwrap()
then panics at each later lock. The 14 sites in LENGTHEN, the HTTP
bridge, the schema cache and the extraction catalog now recover the
data with .unwrap_or_else(|e| e.into_inner()), as the other locks of
the code base do.

Co-Authored-By: Claude
@HakanSeven12
HakanSeven12 merged commit 20f00e8 into HakanSeven12:main Nov 23, 2026
8 checks passed
@travisjhughes
travisjhughes deleted the poisoned-lock-sites branch November 23, 2026 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants