Skip to content

Conversation

@petar-omni
Copy link

Snapshot the listeners array before iteration in Node.notify() to prevent skipping listeners when one unsubscribes itself during notification. The previous implementation iterated directly over this.listeners, which could cause subsequent listeners to be missed when earlier listeners mutated the array via unsubscribe.

Steps to reproduce the bug:

  • Use resultOnce, adds 1 listener now
  • Another listener by someone else is added, so 2 listeners now
  • notify() is called, first listener cleans up itself, mutates listeners array on node
  • 2nd listener in notify() never called

@tim-smart
Copy link
Owner

I took a look at this for effect v4 and ended up switch to a Set. Effect-TS/effect-smol#1173

Feel free to do the same, otherwise I'll backport it later.

@petar-omni petar-omni force-pushed the fix/listeners-tracking branch from c18ab8a to 2c7c48d Compare February 6, 2026 09:54
@petar-omni
Copy link
Author

@tim-smart Ok, did a backport

@tim-smart
Copy link
Owner

Just needs a pnpm changeset

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.

2 participants