From 22957af8aafc161e1324b277ddae5c83f44ca3bc Mon Sep 17 00:00:00 2001 From: xtaci Date: Fri, 27 Dec 2024 22:10:54 +0800 Subject: [PATCH] fix nil pointer exception --- session.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/session.go b/session.go index 19806be..8f6d0a5 100644 --- a/session.go +++ b/session.go @@ -348,9 +348,12 @@ func (s *Session) RemoteAddr() net.Addr { // notify the session that a stream has closed func (s *Session) streamClosed(sid uint32) { s.streamLock.Lock() - if n := s.streams[sid].recycleTokens(); n > 0 { // return remaining tokens to the bucket - if atomic.AddInt32(&s.bucket, int32(n)) > 0 { - s.notifyBucket() + if stream, ok := s.streams[sid]; ok { + n := stream.recycleTokens() + if n > 0 { // return remaining tokens to the bucket + if atomic.AddInt32(&s.bucket, int32(n)) > 0 { + s.notifyBucket() + } } } delete(s.streams, sid)