Skip to content

Commit

Permalink
Avoid to block thread while write to a nil channel
Browse files Browse the repository at this point in the history
if session disconnected during sendBytes, session.messageOut
may be set to nil before write in session.onDisconnect()
  • Loading branch information
tigerlee authored and ackleymi committed May 8, 2023
1 parent 07872e7 commit 3ce9479
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,11 @@ func (s *session) EnqueueBytesAndSend(msg []byte) {
}

func (s *session) sendBytes(msg []byte) {
if s.messageOut == nil {
s.log.OnEventf("Failed to send: disconnected")
return
}

s.log.OnOutgoing(msg)
s.messageOut <- msg
s.stateTimer.Reset(s.HeartBtInt)
Expand Down

0 comments on commit 3ce9479

Please sign in to comment.