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:
copilot-swe-agent[bot]
2026-01-09 11:08:10 +00:00
parent ecef77ff48
commit 41050594e5
2 changed files with 16 additions and 38 deletions
+3 -1
View File
@@ -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,
}