Skip to content

Commit a48ffa3

Browse files
xinfan.wu(吴歆帆)AlexStocks
xinfan.wu(吴歆帆)
andcommitted
fix:add read mutex in gettyWSConn(websocket) struct to prevent data race in ReadMessage().
Co-authored-by: AlexStocks <alexstocks@foxmail.com>
1 parent 57bf5fd commit a48ffa3

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

transport/connection.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ func (w *gettyWSConn) CloseConn(waitSec int) {
644644
w.conn.Close()
645645
}
646646

647-
// uses a mutex to ensure that only one thread can send a message at a time, preventing race conditions.
647+
// uses a mutex(writeLock) to ensure that only one thread can send a message at a time, preventing race conditions.
648648
func (w *gettyWSConn) threadSafeWriteMessage(messageType int, data []byte) error {
649649
w.writeLock.Lock()
650650
defer w.writeLock.Unlock()
@@ -654,7 +654,7 @@ func (w *gettyWSConn) threadSafeWriteMessage(messageType int, data []byte) error
654654
return nil
655655
}
656656

657-
// uses a mutex to ensure that only one thread can read a message at a time, preventing race conditions.
657+
// uses a mutex(readLock) to ensure that only one thread can read a message at a time, preventing race conditions.
658658
func (w *gettyWSConn) threadSafeReadMessage() (int, []byte, error) {
659659
w.readLock.Lock()
660660
defer w.readLock.Unlock()

0 commit comments

Comments
 (0)