Skip to content

Commit

Permalink
fix: do not process incoming messages from closed sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
palkan committed Aug 31, 2023
1 parent 4c0bef4 commit bcf58fb
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions node/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,10 @@ func (s *Session) Serve(callback func()) error {
defer callback()

for {
if s.IsClosed() {
return
}

message, err := s.conn.Read()

if err != nil {
Expand Down Expand Up @@ -520,6 +524,13 @@ func (s *Session) close() {
}
}

func (s *Session) IsClosed() bool {
s.mu.Lock()
defer s.mu.Unlock()

return s.closed
}

func (s *Session) sendClose(reason string, code int) {
s.sendFrame(&ws.SentFrame{
FrameType: ws.CloseFrame,
Expand Down

0 comments on commit bcf58fb

Please sign in to comment.