Skip to content

Commit

Permalink
Add mutex around SendWebsocket
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Jul 22, 2021
1 parent 74cd673 commit c11b089
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions appservice/appservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ type AppService struct {
intentsLock sync.RWMutex

ws *websocket.Conn
wsWriteLock sync.Mutex
StopWebsocket func(error)
WebsocketCommands chan WebsocketCommand
websocketRequests map[int]chan<- *WebsocketCommand
Expand Down
2 changes: 2 additions & 0 deletions appservice/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ func (as *AppService) SendWebsocket(cmd *WebsocketRequest) error {
if as.ws == nil {
return errors.New("websocket not connected")
}
as.wsWriteLock.Lock()
defer as.wsWriteLock.Unlock()
return as.ws.WriteJSON(cmd)
}

Expand Down

0 comments on commit c11b089

Please sign in to comment.