From 5a21bf36424d8cddca9e97ef5c0783fa6b2dfa4a Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Thu, 22 May 2025 17:01:24 +0800 Subject: [PATCH] fix: listener close panic --- common/net/listener.go | 4 ++-- component/tls/httpserver.go | 4 +++- listener/reality/reality.go | 4 +++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/common/net/listener.go b/common/net/listener.go index 0621b6c22..4431ccd3b 100644 --- a/common/net/listener.go +++ b/common/net/listener.go @@ -34,8 +34,8 @@ func (l *handleContextListener) init() { } } }() - if c, err := l.handle(l.ctx, c); err == nil { - l.conns <- c + if conn, err := l.handle(l.ctx, c); err == nil { + l.conns <- conn } else { // handle failed, close the underlying connection. _ = c.Close() diff --git a/component/tls/httpserver.go b/component/tls/httpserver.go index a8c9ed7f0..3ddac4d8e 100644 --- a/component/tls/httpserver.go +++ b/component/tls/httpserver.go @@ -4,6 +4,7 @@ import ( "context" "net" "net/http" + "runtime/debug" "time" N "github.com/metacubex/mihomo/common/net" @@ -63,6 +64,7 @@ func NewListenerForHttps(l net.Listener, httpServer *http.Server, tlsConfig *Con } return c, nil }, func(a any) { - log.Errorln("https server panic: %s", a) + stack := debug.Stack() + log.Errorln("https server panic: %s\n%s", a, stack) }) } diff --git a/listener/reality/reality.go b/listener/reality/reality.go index 036bcf282..64de7cf81 100644 --- a/listener/reality/reality.go +++ b/listener/reality/reality.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "net" + "runtime/debug" "time" N "github.com/metacubex/mihomo/common/net" @@ -89,7 +90,8 @@ func (b Builder) NewListener(l net.Listener) net.Listener { // We fixed it by calling Close() directly. return realityConnWrapper{c}, nil }, func(a any) { - log.Errorln("reality server panic: %s", a) + stack := debug.Stack() + log.Errorln("reality server panic: %s\n%s", a, stack) }) }