Fangliding 9 месяцев назад
Родитель
Сommit
73baf47358
1 измененных файлов с 6 добавлено и 0 удалено
  1. 6 0
      proxy/dns/dns.go

+ 6 - 0
proxy/dns/dns.go

@@ -5,6 +5,7 @@ import (
 	go_errors "errors"
 	go_errors "errors"
 	"io"
 	"io"
 	"sync"
 	"sync"
+	"sync/atomic"
 	"time"
 	"time"
 
 
 	"github.com/xtls/xray-core/common"
 	"github.com/xtls/xray-core/common"
@@ -371,6 +372,7 @@ type outboundConn struct {
 
 
 	closeOnce sync.Once
 	closeOnce sync.Once
 	dialOnce  sync.Once
 	dialOnce  sync.Once
+	closed    atomic.Bool
 
 
 	conn      net.Conn
 	conn      net.Conn
 	connReady chan struct{}
 	connReady chan struct{}
@@ -381,6 +383,9 @@ func (c *outboundConn) dial() error {
 	if err != nil {
 	if err != nil {
 		return err
 		return err
 	}
 	}
+	if c.closed.Load() {
+		return errors.New("connection closed during dial")
+	}
 	c.conn = conn
 	c.conn = conn
 	c.connReady <- struct{}{}
 	c.connReady <- struct{}{}
 	return nil
 	return nil
@@ -423,6 +428,7 @@ func (c *outboundConn) Read(b []byte) (int, error) {
 func (c *outboundConn) Close() error {
 func (c *outboundConn) Close() error {
 	c.closeOnce.Do(func() {
 	c.closeOnce.Do(func() {
 		c.access.Lock()
 		c.access.Lock()
+		c.closed.Store(true)
 		close(c.connReady)
 		close(c.connReady)
 		if c.conn != nil {
 		if c.conn != nil {
 			c.conn.Close()
 			c.conn.Close()