Commit Graph
3 Commits
Author SHA1 Message Date
prakash-dev-code a5f7e1c98a fix(websocket): deliver events to every subscriber of an instance
The websocket producer kept a single connection per instance in
`clients map[string]*websocket.Conn`. Registering a second subscriber
silently replaced the first, and `RemoveClient` deleted the whole instance
entry when either one disconnected. Consuming events in two browser tabs
therefore delivered to only the most recent one, and closing that tab cut
delivery for the remaining subscriber too.

Changes:

- `clients` becomes `map[string][]*client`. Deregistration now matches the
  specific connection instead of removing the instance entry, so sibling
  subscribers keep receiving events.
- Each connection carries its own write mutex. Events are dispatched from
  independent goroutines (the `go CallWebhook` calls in the whatsmeow event
  handler) and gorilla/websocket permits only one concurrent writer per
  connection, so two simultaneous events could interleave writes on the
  same socket.
- `Produce` snapshots the subscriber list under the read lock and performs
  writes outside it, so a slow or half-open socket no longer blocks
  deliveries for other instances.
- Failed writes prune the dead connection, and `Produce` now returns nil.
  `sendToQueueOrWebhook` aborts the remaining producers when one returns an
  error, so a closed browser tab previously suppressed RabbitMQ, NATS and
  webhook delivery for that same event.

Verified with two concurrent subscribers on one instance: both receive
identical event streams, and disconnecting one leaves the other unaffected.

(cherry picked from commit 1db4408244fe75b39c2b4e1bbb8e681679dd7dae)
2026-11-09 12:01:02 -03:00
github-actions[bot] 9337afc47e sync: 0.7.2 from main (6164dced8d3ab8f9bcce9bf333fb4e8663760ff1) 2026-07-03 01:55:33 +00:00
Davidson Gomes 877eef7f07 release: v0.6.1 2026-03-25 12:40:16 -03:00