Skip to content

host: fix sendEvent/RemoveListener deadlock and send-on-closed panic - #8

Merged
phaus merged 1 commit into
mainfrom
fix/host-state-listener
Sep 4, 2026
Merged

host: fix sendEvent/RemoveListener deadlock and send-on-closed panic#8
phaus merged 1 commit into
mainfrom
fix/host-state-listener

Conversation

@phaus

@phaus phaus commented Sep 4, 2026

Copy link
Copy Markdown
Member

sendEvent held the listener read lock while blocking on unbuffered channel sends. A slow or disconnecting listener could block a send indefinitely, preventing RemoveListener from acquiring the write lock and causing a deadlock. It also left a window where RemoveListener could close a channel between sendEvent reading it from the map and sending to it, panicking on a send to a closed channel.

Use non-blocking sends in sendEvent so the read lock is never held while blocked, and close the channel under the write lock in RemoveListener so no send can be in flight when it is closed.

sendEvent held the listener read lock while blocking on unbuffered
channel sends. A slow or disconnecting listener could block a send
indefinitely, preventing RemoveListener from acquiring the write lock
and causing a deadlock. It also left a window where RemoveListener could
close a channel between sendEvent reading it from the map and sending to
it, panicking on a send to a closed channel.

Use non-blocking sends in sendEvent so the read lock is never held while
blocked, and close the channel under the write lock in RemoveListener so
no send can be in flight when it is closed.
@phaus
phaus merged commit 71d9f65 into main Sep 4, 2026
2 checks passed
@phaus
phaus deleted the fix/host-state-listener branch September 4, 2026 09:05
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