Skip to content

Commit

Permalink
Merge pull request #1165 from liaohongxing/main
Browse files Browse the repository at this point in the history
SocketIO: Change isAlive to atomic update to solve the high concurrency problem
  • Loading branch information
ReneWerner87 authored Sep 2, 2024
2 parents 0531238 + dadd0c8 commit 27e7861
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions socketio/socketio.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ type ws interface {
}

type Websocket struct {
mu sync.RWMutex
once sync.Once
mu sync.RWMutex
// The Fiber.Websocket connection
Conn *websocket.Conn
// Define if the connection is alive or not
Expand Down Expand Up @@ -568,9 +569,11 @@ func (kws *Websocket) disconnected(err error) {

// may be called multiple times from different go routines
if kws.IsAlive() {
close(kws.done)
kws.once.Do(func() {
kws.setAlive(false)
close(kws.done)
})
}
kws.setAlive(false)

// Fire error event if the connection is
// disconnected by an error
Expand Down

0 comments on commit 27e7861

Please sign in to comment.