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 2 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
6 changes: 4 additions & 2 deletions socketio/socketio.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,13 +564,15 @@ func (kws *Websocket) read(ctx context.Context) {

// When the connection closes, disconnected method
func (kws *Websocket) disconnected(err error) {
kws.fireEvent(EventDisconnect, nil, err)
kws.mu.Lock()
defer kws.mu.Unlock()

// may be called multiple times from different go routines
if kws.IsAlive() {
kws.setAlive(false)
close(kws.done)
kws.fireEvent(EventDisconnect, nil, err)
}
kws.setAlive(false)

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