Concurrent websocket write bug #21
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
hub.go:63: Hub.Emit callsc.WriteMessage(...)directly on shared*websocket.Connvalues with no per-connection write serialization.gorilla/websocketrequires one concurrent writer per connection. If two goroutines callEmitat the same time, they can write to the same socket concurrently and panic with concurrent write to websocket connection.3f5d913added a second periodic emitter path by splitting stats and heartbeat into separate goroutines inserver.go:221andapp.go:100. That makes overlappinghub.Emitcalls more likely.91fad39066) did not change the WebSocket hub logic. It still passeshub.Emitfrom the same places and does not add any locking around writes.One nuance:
3f5d913, ingest could already emit from MQTT handling while the stats ticker emitted from another goroutine, viaservice.go:255and the others.emitter.Emit(...)calls. So the bug existed already.3f5d913likely increased the reproduction rate by adding another independent emitter.So my assessment is:
3f5d913.internal/api/ws/hub.gonot enforcing single-writer semantics.Natural next steps: