Skip to content

(bug) Possible deadlock in the websocket service #3144

@Vizualni

Description

@Vizualni

Observed behaviour

Apologizes for not testing this, but rather I am simply reporting it as I've noticed this while exploring the codebase. It seems that there might be a deadlocking situation happening in the websocket service.

func (w *websocketServiceImpl) BroadcastFlagChanges(diff notifier.DiffCache) {
w.mutex.RLock()
defer w.mutex.RUnlock()
for c := range w.clients {
err := c.WriteJSON(diff)
if err != nil {
w.Deregister(c)
}
}
}

In the BroadcastFlagChanges we are RLock-ing the mutex, but if writing the message to a client fails, we will Deregister them, and the Deregister is getting the Lock:

func (w *websocketServiceImpl) Deregister(c WebsocketConn) {
w.mutex.Lock()
defer w.mutex.Unlock()
delete(w.clients, c)
}

As you can't upgrade the RWLock, this can block the whole server.

Expected Behavior

No deadlock to happen.

Steps to reproduce

No response

Metadata

Metadata

Labels

bugSomething isn't workingpriority:P1High priority

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions