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

Remove lock from sessionWS.SendBytes #1140

Merged
merged 2 commits into from
Jan 24, 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
12 changes: 2 additions & 10 deletions server/session_ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,24 +400,17 @@ func (s *sessionWS) Send(envelope *rtapi.Envelope, reliable bool) error {
}

func (s *sessionWS) SendBytes(payload []byte, reliable bool) error {
s.Lock()
if s.stopped {
s.Unlock()
return nil
}

// Attempt to queue messages and observe failures.
select {
case s.outgoingCh <- payload:
s.Unlock()
return nil
default:
// The outgoing queue is full, likely because the remote client can't keep up.
// Terminate the connection immediately because the only alternative that doesn't block the server is
// to start dropping messages, which might cause unexpected behaviour.
s.Unlock()
s.logger.Warn("Could not write message, session outgoing queue full")
s.Close(ErrSessionQueueFull.Error(), runtime.PresenceReasonDisconnect)
// Close in a goroutine as the method can block
go s.Close(ErrSessionQueueFull.Error(), runtime.PresenceReasonDisconnect)
return ErrSessionQueueFull
}
}
Expand Down Expand Up @@ -460,7 +453,6 @@ func (s *sessionWS) Close(msg string, reason runtime.PresenceReason, envelopes .

// Clean up internals.
s.pingTimer.Stop()
close(s.outgoingCh)

// Send final messages, if any are specified.
for _, envelope := range envelopes {
Expand Down
Loading