Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SocketIO: Change isAlive to atomic update to solve the high concurrency problem #1165

Merged
merged 5 commits into from
Sep 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading