From a6aca101d62084ff7f27ee695448610aebc500ba Mon Sep 17 00:00:00 2001 From: LjhAUMEM Date: Sun, 18 Jan 2026 12:25:36 +0800 Subject: [PATCH] Hysteria outbound: Fix ContextWithRequireDatagram() (#5558) Fixes https://github.com/XTLS/Xray-core/pull/5549 --- proxy/hysteria/client.go | 5 +---- proxy/hysteria/ctx/ctx.go | 5 ++++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/proxy/hysteria/client.go b/proxy/hysteria/client.go index 6325261a..2299fe34 100644 --- a/proxy/hysteria/client.go +++ b/proxy/hysteria/client.go @@ -56,10 +56,7 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter ob.CanSpliceCopy = 3 target := ob.Target - if target.Network == net.Network_UDP { - hyCtx.ContextWithRequireDatagram(ctx) - } - conn, err := dialer.Dial(ctx, c.server.Destination) + conn, err := dialer.Dial(hyCtx.ContextWithRequireDatagram(ctx, target.Network == net.Network_UDP), c.server.Destination) if err != nil { return errors.New("failed to find an available destination").AtWarning().Base(err) } diff --git a/proxy/hysteria/ctx/ctx.go b/proxy/hysteria/ctx/ctx.go index 6c03a101..610fa065 100644 --- a/proxy/hysteria/ctx/ctx.go +++ b/proxy/hysteria/ctx/ctx.go @@ -10,7 +10,10 @@ const ( requireDatagram key = iota ) -func ContextWithRequireDatagram(ctx context.Context) context.Context { +func ContextWithRequireDatagram(ctx context.Context, udp bool) context.Context { + if !udp { + return ctx + } return context.WithValue(ctx, requireDatagram, struct{}{}) }