diff --git a/node/session.go b/node/session.go index cf3dd772..d2d7bd26 100644 --- a/node/session.go +++ b/node/session.go @@ -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 { @@ -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,