Skip to content

fix(service): stop an unsubscribe from deadlocking the bus - #3

Merged
inkly merged 1 commit into
mainfrom
fix/unsubscribe-deadlock
Sep 25, 2026
Merged

inkly merged 1 commit into
mainfrom
fix/unsubscribe-deadlock

Conversation

@inkly

@inkly inkly commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator

A websocket closing while it was not the first subscriber of an event deadlocked the bus: Unsubscribe locked the mutex once per subscriber it looked at, each unlock deferred. Every subscription after that hung once its websocket was open, which is why the core's push alerts never received backup:error in the v0.5.10 install check.

  • lock once per call, in EventServiceWS and ActionServiceWS
  • the dispatch reads the subscriber lists under the lock
  • a publish waits for the dispatch instead of dropping the event; subscribers get a buffer of 64

Tests: TestUnsubscribeASubscriberAfterTheFirst deadlocks on the old code; TestEventsPublishedTogetherAllArrive.

Unsubscribe took the lock once per subscriber it looked at, each unlock
deferred to its return: a websocket closing while it was not the first
subscriber of an event locked the bus's mutex twice and never came back.
Every subscription after it hung once its websocket was open, so the
subscriber believed it was listening and received nothing. The core's
alerts, which resubscribe each time the core restarts, hit it on every
install check: three connections closed together, the third deadlocked.

The lock is now taken once per call, in both services. The dispatch reads
the subscriber lists under it too, as a map read while Subscribe writes it
can bring the bus down. And two silent drops go: a publish waits for the
dispatch instead of dropping an event it is busy with, and a subscriber
may be 64 events behind instead of one.
@inkly
inkly merged commit 5249d64 into main Sep 25, 2026
1 check passed
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.

1 participant