From 81e134219fe150f8824ea42dbab2528b80bd1918 Mon Sep 17 00:00:00 2001 From: Fangliding Date: Sat, 2 May 2026 02:57:42 +0800 Subject: [PATCH 1/3] Better UDP blackhole --- proxy/blackhole/blackhole.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/proxy/blackhole/blackhole.go b/proxy/blackhole/blackhole.go index 998666cbfd80..a099064fc5b7 100644 --- a/proxy/blackhole/blackhole.go +++ b/proxy/blackhole/blackhole.go @@ -6,7 +6,10 @@ import ( "time" "github.com/xtls/xray-core/common" + "github.com/xtls/xray-core/common/buf" + "github.com/xtls/xray-core/common/net" "github.com/xtls/xray-core/common/session" + "github.com/xtls/xray-core/common/signal" "github.com/xtls/xray-core/transport" "github.com/xtls/xray-core/transport/internet" ) @@ -38,7 +41,17 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte // Sleep a little here to make sure the response is sent to client. time.Sleep(time.Second) } - common.Interrupt(link.Writer) + defer common.Interrupt(link.Writer) + defer common.Interrupt(link.Reader) + // wait to drain all the possible incoming UDP data + if ob.Target.Network == net.Network_UDP { + ctx, cancel := context.WithCancel(ctx) + timer := signal.CancelAfterInactivity(ctx, func() { + cancel() + }, 60*time.Second) + go buf.Copy(link.Reader, buf.Discard, buf.UpdateActivity(timer)) + <-ctx.Done() + } return nil } From 5d40aad82d2d5f55e4b44710eed6342565aa7e6c Mon Sep 17 00:00:00 2001 From: Meo597 <197331664+Meo597@users.noreply.github.com> Date: Sat, 2 May 2026 20:53:57 +0800 Subject: [PATCH 2/3] rand 30-90 --- proxy/blackhole/blackhole.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/proxy/blackhole/blackhole.go b/proxy/blackhole/blackhole.go index a099064fc5b7..217ce7f0f2f9 100644 --- a/proxy/blackhole/blackhole.go +++ b/proxy/blackhole/blackhole.go @@ -7,6 +7,7 @@ import ( "github.com/xtls/xray-core/common" "github.com/xtls/xray-core/common/buf" + "github.com/xtls/xray-core/common/dice" "github.com/xtls/xray-core/common/net" "github.com/xtls/xray-core/common/session" "github.com/xtls/xray-core/common/signal" @@ -48,7 +49,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte ctx, cancel := context.WithCancel(ctx) timer := signal.CancelAfterInactivity(ctx, func() { cancel() - }, 60*time.Second) + }, time.Duration(30+dice.Roll(91))*time.Second) go buf.Copy(link.Reader, buf.Discard, buf.UpdateActivity(timer)) <-ctx.Done() } From 0bd1caf501ff5b17a2d7e24981a3c427b2e7c3fd Mon Sep 17 00:00:00 2001 From: RPRX <63339210+RPRX@users.noreply.github.com> Date: Sat, 2 May 2026 15:26:47 +0000 Subject: [PATCH 3/3] Update blackhole.go --- proxy/blackhole/blackhole.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxy/blackhole/blackhole.go b/proxy/blackhole/blackhole.go index 217ce7f0f2f9..17350d156e83 100644 --- a/proxy/blackhole/blackhole.go +++ b/proxy/blackhole/blackhole.go @@ -49,7 +49,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte ctx, cancel := context.WithCancel(ctx) timer := signal.CancelAfterInactivity(ctx, func() { cancel() - }, time.Duration(30+dice.Roll(91))*time.Second) + }, time.Duration(30+dice.Roll(61))*time.Second) go buf.Copy(link.Reader, buf.Discard, buf.UpdateActivity(timer)) <-ctx.Done() }