Skip to content

fix bug EventBus::broadcast#4425

Open
songgaoye wants to merge 1 commit intoinformalsystems:masterfrom
songgaoye:fix_eventbus_broadcast
Open

fix bug EventBus::broadcast#4425
songgaoye wants to merge 1 commit intoinformalsystems:masterfrom
songgaoye:fix_eventbus_broadcast

Conversation

@songgaoye
Copy link
Copy Markdown

@songgaoye songgaoye commented Jan 16, 2026

Closes: #XXX

pub fn broadcast(&mut self, value: T)
where
T: Clone,
{
let mut disconnected = Vec::new();
for (idx, tx) in self.txs.iter().enumerate() {
// TODO: Avoid cloning when sending to last subscriber
if let Err(channel::SendError(_)) = tx.send(value.clone()) {
disconnected.push(idx);
}
}
// Remove all disconnected subscribers
for idx in disconnected {

The original code has a correctness bug:

Collecting indices [0, 2, 5] to remove
After remove(0), index 2 becomes 1, index 5 becomes 4
Removes wrong elements!

Description


PR author checklist:

  • Added changelog entry, using unclog.
  • Added tests: integration (for Hermes) or unit/mock tests (for modules).
  • Linked to GitHub issue.
  • Updated code comments and documentation (e.g., docs/).
    • If guide has been updated, tag GitHub user mircea-c
  • Tagged one reviewer who will be the one responsible for shepherding this PR.

Reviewer checklist:

  • Reviewed Files changed in the GitHub PR explorer.
  • Manually tested (in case integration/unit/mock tests are absent).

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