From 54ae7b1cd5f9a4701e1a401ef567ed86ee5f0e5e Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Tue, 27 Jul 2021 21:34:01 +0100 Subject: [PATCH] Don't panic when callbacks aren't set --- conn.go | 4 +++- socket.go | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/conn.go b/conn.go index 1d4519f..cf8ef32 100644 --- a/conn.go +++ b/conn.go @@ -616,5 +616,7 @@ func (c *Conn) detach() { s.lazyDestroy() s.onMutex.RLock() defer s.onMutex.RUnlock() - go s.onDetach(c.remoteSocketAddr) + if s.onDetach != nil { + go s.onDetach(c.remoteSocketAddr) + } } diff --git a/socket.go b/socket.go index cfe5ebe..eace399 100644 --- a/socket.go +++ b/socket.go @@ -445,7 +445,9 @@ func (s *Socket) registerConn(recvID uint16, remoteAddr resolvedAddrStr, c *Conn s.conns[key] = c s.onMutex.RLock() defer s.onMutex.RUnlock() - go s.onAttach(c.remoteSocketAddr) + if s.onAttach != nil { + go s.onAttach(c.remoteSocketAddr) + } return true }