Media-source sign-out/disconnect handlers leak their EntityLocker on exception (no finally) — permanent 409 #256

Closed
opened 2026-07-11 15:06:28 +02:00 by timothy · 1 comment
Owner

Severity: High (lock lifecycle). Pre-existing latent bug, surfaced during the #202 pre-review (Codex, verified against source). Same class as the reviewer#20 async-lock audit (#231–#235); different code path.

What's wrong

SignOutOfPlexHandler.cs:28 and DisconnectJellyfinHandler.cs:29 (Emby structurally identical) release their family IEntityLocker lock only after all work succeeds — repo deletion, search-index commit, secret-store deletion — with no finally. If any awaited dependency throws, the lock is never released.

Today Blazor acquires the lock in the page and the throw surfaces as a snackbar, so the leak is partially masked. But #202's REST design has the controller acquire the family lock before dispatch and the handler release it; a throw from any awaited dependency then leaves every future sign-out/disconnect returning 409 until process restart.

Fix (being done within #202, per scope decision on the tracker)

Single explicit lock owner; the handler wraps its work in try { … } finally { Unlock…(); } so release happens on every non-handoff exit. Fault-injection tests substituting a throwing dependency per awaited call, asserting the lock ends released.

Filed for record — fix ships within #202 (design doc §C6). Cross-refs: #202, adversarial-reviewer#19 (slice 2), adversarial-reviewer#20 / #231–#235 (same lock-lifecycle discipline).

**Severity: High (lock lifecycle).** Pre-existing latent bug, surfaced during the #202 pre-review (Codex, verified against source). Same class as the reviewer#20 async-lock audit (#231–#235); different code path. ## What's wrong `SignOutOfPlexHandler.cs:28` and `DisconnectJellyfinHandler.cs:29` (Emby structurally identical) release their family `IEntityLocker` lock **only after** all work succeeds — repo deletion, search-index commit, secret-store deletion — with **no `finally`**. If any awaited dependency throws, the lock is never released. Today Blazor acquires the lock in the page and the throw surfaces as a snackbar, so the leak is partially masked. But #202's REST design has the **controller acquire the family lock before dispatch** and the handler release it; a throw from any awaited dependency then leaves every future sign-out/disconnect returning **409 until process restart**. ## Fix (being done within #202, per scope decision on the tracker) Single explicit lock owner; the handler wraps its work in `try { … } finally { Unlock…(); }` so release happens on every non-handoff exit. Fault-injection tests substituting a throwing dependency per awaited call, asserting the lock ends released. Filed **for record** — fix ships within #202 (design doc §C6). Cross-refs: #202, adversarial-reviewer#19 (slice 2), adversarial-reviewer#20 / #231–#235 (same lock-lifecycle discipline).
timothy added the bugreview labels 2026-07-11 15:06:28 +02:00
Author
Owner

Fixed in PR #262 (merged to main 8e2f9954, #202). SignOutOfPlexHandler / DisconnectJellyfinHandler / DisconnectEmbyHandler now release their family IEntityLocker lock in a try/finally, so a throw from any awaited dependency (repo delete, search-index, secret store) still releases — no permanent 409 wedge. Fault-injection tests assert release under a throwing dependency.

Fixed in PR #262 (merged to main `8e2f9954`, #202). `SignOutOfPlexHandler` / `DisconnectJellyfinHandler` / `DisconnectEmbyHandler` now release their family `IEntityLocker` lock in a `try/finally`, so a throw from any awaited dependency (repo delete, search-index, secret store) still releases — no permanent 409 wedge. Fault-injection tests assert release under a throwing dependency.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: timothy/ersatztv#256