From c886c09b7164c86a68a7a7cae9a234cfdb3db0b0 Mon Sep 17 00:00:00 2001 From: Andeya Date: Thu, 12 Dec 2024 14:52:43 +0800 Subject: [PATCH] fix: Fix the problem of "panic" when reading or writing packets caused by the closure of the connection. #106 --- socket/socket.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/socket/socket.go b/socket/socket.go index f9bd765..5557a71 100644 --- a/socket/socket.go +++ b/socket/socket.go @@ -219,6 +219,9 @@ func (s *socket) WriteMessage(message Message) error { s.mu.RLock() protocol := s.protocol s.mu.RUnlock() + if protocol == nil { + return ErrProactivelyCloseSocket + } err := protocol.Pack(message) if err != nil && s.isActiveClosed() { err = ErrProactivelyCloseSocket @@ -235,6 +238,9 @@ func (s *socket) ReadMessage(message Message) error { s.mu.RLock() protocol := s.protocol s.mu.RUnlock() + if protocol == nil { + return ErrProactivelyCloseSocket + } return protocol.Unpack(message) }