Skip to content

Fix LocalSharedStorage electing a second owner when the owner is busy - #4186

Open
T4rk1n wants to merge 3 commits into
devfrom
fix/local-storage-busy-owner
Open

T4rk1n wants to merge 3 commits into
devfrom
fix/local-storage-busy-owner

Conversation

@T4rk1n

@T4rk1n T4rk1n commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Under load, LocalSharedStorage could elect a second owner while the first was still running. The new owner started with an empty store, so every open stream got a reset.

A worker that can't reach the owner re-elects. _unix_is_stale decided whether the owner's socket file was dead with a connect probe, and treated any OSError as dead. A live owner too busy to accept (its listen(128) backlog full, so the 0.5 s probe times out) was judged dead. The worker then unlinked its socket and bound a new one, splitting the store in two. With 4 uvicorn workers at 4000 streaming browsers this happened in about 2 of 11 runs, and every downlink reset.

The probe now decides:

  • Refused or no file: dead. On Linux a refusal only means nobody listens.
  • Not a socket: stale, so a stray file is still cleaned up.
  • Timeout or full backlog: alive, so the worker stays a client of the current owner.
  • macOS and the BSDs also refuse on a full backlog, so there a refusal means dead only once the owner's process is gone. The owner now writes its pid in the .addr advertisement. An advertisement from an older Dash has no pid and keeps the old behavior.

Tests in tests/shared_storage/test_local_cross_process.py:

  • test_busy_owner_is_not_replaced pauses the owner process with SIGSTOP and fills its accept backlog. A client that re-elects must stay a client and still read the owner's data after SIGCONT. It fails without the fix.
  • test_stale_socket_probe covers a missing file, a socket file with no listener, a stray regular file, and the macOS rule (live pid, dead pid, no advertisement).
  • test_reelection_after_owner_killed still passes: a killed owner is still replaced.

Load test (4 uvicorn workers, 4000 browsers, with #4184 merged in locally so its cut-off streams don't hide the result): 6 runs back to back, no resets and no errors.

@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Dash performance benchmarks

✅ all within thresholds

scenario metric p90 (ms) median growth baseline p90 note
✅ callback_chain chain_ms 323.4 315.2 0.93x 499.1
✅ callback_chain graph_ms 1.3 1.3 1.0x 2.4
✅ callback_fanout fanout_ms 57.0 51.3 0.89x 92.5
✅ deep_nesting render_ms 36.4 35.0 1.02x 56.8
✅ full_children_replace replace_ms 106.3 68.0 2.94x -
✅ initial_render_large render_ms 366.4 345.3 1.37x 694.4
✅ initial_render_small render_ms 78.9 58.2 0.87x 104.0
✅ patch_append_nested append_ms 79.0 54.9 2.48x 192.3
✅ patch_append_toplevel append_ms 70.1 52.2 2.06x 140.2
✅ patch_scalar_update_large update_ms 87.0 80.5 0.99x 202.9
✅ rerender_existing_subtree rerender_ms 75.6 62.6 0.89x -
✅ wildcard_all_resolve wildcard_ms 198.3 189.4 0.95x 313.6
✅ wildcard_all_resolve graph_ms 0.8 0.8 1.0x 1.3

growth = late-third / early-third per-op time; ~1 is flat, a large value means the per-op cost scales with accumulated state.

machine scale vs baseline: 0.61x - divided out of the baseline ratios so they compare like for like (the absolute warn/fail ceilings are left un-scaled); calibrated on initial_render_small.

@sonarqubecloud

Copy link
Copy Markdown

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