mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-07-02 17:58:46 +00:00
Fix multi-peer WireGuard by using detached context for bind
The issue was in client.go, not server.go. When WireGuard is used as an outbound with multiple peers, all peers were sharing the same context from the first connection. This caused all subsequent peer connections to be associated with the first connection's session ID, leading to routing failures. The fix uses core.ToBackgroundDetachedContext() to create an independent context for the netBindClient, allowing each peer connection to work independently with its own session context. - Reverted incorrect changes to server.go - Fixed client.go to use detached context for the bind - Tests pass successfully Co-authored-by: RPRX <63339210+RPRX@users.noreply.github.com>
This commit is contained in:
@@ -114,6 +114,8 @@ func (h *Handler) processWireGuard(ctx context.Context, dialer internet.Dialer)
|
||||
}
|
||||
|
||||
// bind := conn.NewStdNetBind() // TODO: conn.Bind wrapper for dialer
|
||||
// Use a detached context for the bind to avoid tying all peer connections
|
||||
// to a single request context. This allows multiple peers to work independently.
|
||||
h.bind = &netBindClient{
|
||||
netBind: netBind{
|
||||
dns: h.dns,
|
||||
@@ -123,7 +125,7 @@ func (h *Handler) processWireGuard(ctx context.Context, dialer internet.Dialer)
|
||||
},
|
||||
workers: int(h.conf.NumWorkers),
|
||||
},
|
||||
ctx: ctx,
|
||||
ctx: core.ToBackgroundDetachedContext(ctx),
|
||||
dialer: dialer,
|
||||
reserved: h.conf.Reserved,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user