mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-12-12 12:42:26 +04:00
prevent close of closed
This commit is contained in:
@@ -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()
|
||||||
|
|||||||
Reference in New Issue
Block a user