Skip to content

fix: prevent race condition and panic in events.Producer.Broadcast#4180

Closed
Lil-Duckling-22 wants to merge 1 commit intoOffchainLabs:masterfrom
Lil-Duckling-22:fix/events-producer-broadcast-race-condition
Closed

fix: prevent race condition and panic in events.Producer.Broadcast#4180
Lil-Duckling-22 wants to merge 1 commit intoOffchainLabs:masterfrom
Lil-Duckling-22:fix/events-producer-broadcast-race-condition

Conversation

@Lil-Duckling-22
Copy link
Copy Markdown

Fix race condition in events.Producer.Broadcast that caused panics when subscriptions were cancelled concurrently with broadcasts. Copy subscription list under lock and add recover() to handle closed channel panics.

Without this fix, the application crashes with "send on closed channel" panic when Next() closes a subscription channel while Broadcast sends to it.

Fix race condition in events.Producer.Broadcast that caused panics when
subscriptions were cancelled concurrently with broadcasts. Copy subscription
list under lock and add recover() to handle closed channel panics.

Without this fix, the application crashes with "send on closed channel"
panic when Next() closes a subscription channel while Broadcast sends to it.
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Dec 29, 2025

CLA assistant check
All committers have signed the CLA.

@rauljordan
Copy link
Copy Markdown
Contributor

This PR has a fundamental problem. Consider the following:

  1. You copy subs under read lock
  2. You release the lock
  3. A subscription could be cancelled and its channel closed in Start()
  4. Your goroutines then try to send on the closed channel, causing a panic
    the panic recovery is hiding a fundamental design flaw, and I think this PR doesn't introduce any improvements that are noteworthy unfortunately. We will have to close

@rauljordan rauljordan closed this Jan 12, 2026
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.

3 participants