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:
Mishalski
2026-11-18 12:14:26 +00:00
committed by GitHub
co-authored by Meow
parent 381e450943
commit b1905088c3
+7 -5
View File
@@ -5,6 +5,7 @@ import (
goerrors "errors"
"io"
"sync"
"sync/atomic"
"time"
"github.com/xtls/xray-core/common"
@@ -24,7 +25,7 @@ type connEntry struct {
link *transport.Link
timer *signal.ActivityTimer
cancel context.CancelFunc
closed bool
closed atomic.Bool
}
func (c *connEntry) Close() error {
@@ -33,10 +34,9 @@ func (c *connEntry) Close() error {
}
func (c *connEntry) terminate() {
if c.closed {
if c.closed.Swap(true) {
panic("terminate called more than once")
}
c.closed = true
c.cancel()
common.Interrupt(c.link.Reader)
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.closed {
if v.conn.closed.Load() {
v.conn = nil
} else {
return v.conn, nil
@@ -144,7 +144,9 @@ func handleInput(ctx context.Context, conn *connEntry, dest net.Destination, cal
mb, err := input.ReadMultiBuffer()
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")
}
return