From 73baf4735812df02efa47c53204e9278dfc83c22 Mon Sep 17 00:00:00 2001 From: Fangliding Date: Mon, 25 Aug 2025 13:55:17 +0800 Subject: [PATCH] prevent close of closed --- proxy/dns/dns.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/proxy/dns/dns.go b/proxy/dns/dns.go index 13f1e52b..4f3b10a5 100644 --- a/proxy/dns/dns.go +++ b/proxy/dns/dns.go @@ -5,6 +5,7 @@ import ( go_errors "errors" "io" "sync" + "sync/atomic" "time" "github.com/xtls/xray-core/common" @@ -371,6 +372,7 @@ type outboundConn struct { closeOnce sync.Once dialOnce sync.Once + closed atomic.Bool conn net.Conn connReady chan struct{} @@ -381,6 +383,9 @@ func (c *outboundConn) dial() error { if err != nil { return err } + if c.closed.Load() { + return errors.New("connection closed during dial") + } c.conn = conn c.connReady <- struct{}{} return nil @@ -423,6 +428,7 @@ func (c *outboundConn) Read(b []byte) (int, error) { func (c *outboundConn) Close() error { c.closeOnce.Do(func() { c.access.Lock() + c.closed.Store(true) close(c.connReady) if c.conn != nil { c.conn.Close()