Skip to content

Commit a464782

Browse files
committed
Try avoiding possible lock
1 parent 605af28 commit a464782

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

ship/websocket.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func (w *websocketConnection) readWebsocketMessage() ([]byte, error) {
157157
// close the current websocket connection
158158
func (w *websocketConnection) close() {
159159
w.shutdownOnce.Do(func() {
160-
if w.isConnectionClosed {
160+
if w.isConnClosed() {
161161
return
162162
}
163163

@@ -193,13 +193,17 @@ func (w *websocketConnection) InitDataProcessing(dataProcessing ShipDataProcessi
193193

194194
// write a message to the websocket connection
195195
func (w *websocketConnection) WriteMessageToDataConnection(message []byte) error {
196-
if w.conn == nil || w.shipWriteChannel == nil || w.isConnClosed() {
197-
return errors.New("connection is not initialized")
196+
if w.isConnClosed() {
197+
return errors.New("connection is closed")
198198
}
199199

200200
w.mux.Lock()
201201
defer w.mux.Unlock()
202202

203+
if w.conn == nil || w.shipWriteChannel == nil {
204+
return errors.New("connection is closed")
205+
}
206+
203207
w.shipWriteChannel <- message
204208
return nil
205209
}

0 commit comments

Comments
 (0)