Skip to content

Commit c886c09

Browse files
committed
fix: Fix the problem of "panic" when reading or writing packets caused by the closure of the connection. #106
1 parent 1580553 commit c886c09

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

socket/socket.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,9 @@ func (s *socket) WriteMessage(message Message) error {
219219
s.mu.RLock()
220220
protocol := s.protocol
221221
s.mu.RUnlock()
222+
if protocol == nil {
223+
return ErrProactivelyCloseSocket
224+
}
222225
err := protocol.Pack(message)
223226
if err != nil && s.isActiveClosed() {
224227
err = ErrProactivelyCloseSocket
@@ -235,6 +238,9 @@ func (s *socket) ReadMessage(message Message) error {
235238
s.mu.RLock()
236239
protocol := s.protocol
237240
s.mu.RUnlock()
241+
if protocol == nil {
242+
return ErrProactivelyCloseSocket
243+
}
238244
return protocol.Unpack(message)
239245
}
240246

0 commit comments

Comments
 (0)