Skip to content

Commit 27e7861

Browse files
authored
Merge pull request #1165 from liaohongxing/main
SocketIO: Change isAlive to atomic update to solve the high concurrency problem
2 parents 0531238 + dadd0c8 commit 27e7861

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

socketio/socketio.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ type ws interface {
125125
}
126126

127127
type Websocket struct {
128-
mu sync.RWMutex
128+
once sync.Once
129+
mu sync.RWMutex
129130
// The Fiber.Websocket connection
130131
Conn *websocket.Conn
131132
// Define if the connection is alive or not
@@ -568,9 +569,11 @@ func (kws *Websocket) disconnected(err error) {
568569

569570
// may be called multiple times from different go routines
570571
if kws.IsAlive() {
571-
close(kws.done)
572+
kws.once.Do(func() {
573+
kws.setAlive(false)
574+
close(kws.done)
575+
})
572576
}
573-
kws.setAlive(false)
574577

575578
// Fire error event if the connection is
576579
// disconnected by an error

0 commit comments

Comments
 (0)