mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-11-30 13:48:36 +00:00
transport/internet/udp/dispatcher.go: Avoid info-level read failure after local session termination; Fix race (#7411)
https://github.com/XTLS/Xray-core/issues/4621#issuecomment-2803983542 https://github.com/XTLS/Xray-core/pull/7411#issuecomment-6893907446 https://github.com/XTLS/Xray-core/pull/7364#issuecomment-6915895563 --------- Co-authored-by: Meow <197331664+Meo597@users.noreply.github.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
|||||||
goerrors "errors"
|
goerrors "errors"
|
||||||
"io"
|
"io"
|
||||||
"sync"
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/xtls/xray-core/common"
|
"github.com/xtls/xray-core/common"
|
||||||
@@ -24,7 +25,7 @@ type connEntry struct {
|
|||||||
link *transport.Link
|
link *transport.Link
|
||||||
timer *signal.ActivityTimer
|
timer *signal.ActivityTimer
|
||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
closed bool
|
closed atomic.Bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *connEntry) Close() error {
|
func (c *connEntry) Close() error {
|
||||||
@@ -33,10 +34,9 @@ func (c *connEntry) Close() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *connEntry) terminate() {
|
func (c *connEntry) terminate() {
|
||||||
if c.closed {
|
if c.closed.Swap(true) {
|
||||||
panic("terminate called more than once")
|
panic("terminate called more than once")
|
||||||
}
|
}
|
||||||
c.closed = true
|
|
||||||
c.cancel()
|
c.cancel()
|
||||||
common.Interrupt(c.link.Reader)
|
common.Interrupt(c.link.Reader)
|
||||||
common.Interrupt(c.link.Writer)
|
common.Interrupt(c.link.Writer)
|
||||||
@@ -77,7 +77,7 @@ func (v *Dispatcher) getInboundRay(ctx context.Context, dest net.Destination) (*
|
|||||||
}
|
}
|
||||||
|
|
||||||
if v.conn != nil {
|
if v.conn != nil {
|
||||||
if v.conn.closed {
|
if v.conn.closed.Load() {
|
||||||
v.conn = nil
|
v.conn = nil
|
||||||
} else {
|
} else {
|
||||||
return v.conn, nil
|
return v.conn, nil
|
||||||
@@ -144,7 +144,9 @@ func handleInput(ctx context.Context, conn *connEntry, dest net.Destination, cal
|
|||||||
|
|
||||||
mb, err := input.ReadMultiBuffer()
|
mb, err := input.ReadMultiBuffer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !goerrors.Is(err, io.EOF) {
|
if conn.closed.Load() {
|
||||||
|
errors.LogDebugInner(ctx, err, "UDP input closed locally")
|
||||||
|
} else if !goerrors.Is(err, io.EOF) {
|
||||||
errors.LogInfoInner(ctx, err, "failed to handle UDP input")
|
errors.LogInfoInner(ctx, err, "failed to handle UDP input")
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user