Skip to content

Commit

Permalink
fix: Fix the problem of "panic" when reading or writing packets cause…
Browse files Browse the repository at this point in the history
…d by the closure of the connection. #106
  • Loading branch information
andeya committed Dec 12, 2024
1 parent 1580553 commit c886c09
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions socket/socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}

Expand Down

0 comments on commit c886c09

Please sign in to comment.