diff --git a/session.go b/session.go index 6ae8527..b2e7faa 100644 --- a/session.go +++ b/session.go @@ -562,6 +562,11 @@ func (s *session) run() { func (s *session) addTask(pkg interface{}) { f := func() { + // If the session is closed, there is no need to perform CPU-intensive operations. + if s.IsClosed() { + log.Errorf("[Id:%d, name=%s, endpoint=%s] Session is closed", s.ID(), s.name, s.EndPoint()) + return + } s.listener.OnMessage(s, pkg) s.IncReadPkgNum() }