From 4899e53c2d05abe8b19f60efcbc355cf8edf53cf Mon Sep 17 00:00:00 2001 From: tomholford Date: Tue, 5 May 2026 18:24:34 -0700 Subject: [PATCH] reverseproxy: use sync.WaitGroup.Go in WebTransport pump Replace the wg.Add(6) + six "go func() { defer wg.Done(); fn() }()" calls with sync.WaitGroup.Go (Go 1.25+, the project's minimum version). Same number of goroutines; less boilerplate. --- modules/caddyhttp/reverseproxy/webtransport_pump.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/modules/caddyhttp/reverseproxy/webtransport_pump.go b/modules/caddyhttp/reverseproxy/webtransport_pump.go index d73944014..bbf2db768 100644 --- a/modules/caddyhttp/reverseproxy/webtransport_pump.go +++ b/modules/caddyhttp/reverseproxy/webtransport_pump.go @@ -57,19 +57,18 @@ type webtransportPump struct { func (p *webtransportPump) run() { var wg sync.WaitGroup - wg.Add(6) // Bidirectional streams in both directions. - go func() { defer wg.Done(); p.acceptBidi(p.client, p.upstream, p.closeUpstream) }() - go func() { defer wg.Done(); p.acceptBidi(p.upstream, p.client, p.closeClient) }() + wg.Go(func() { p.acceptBidi(p.client, p.upstream, p.closeUpstream) }) + wg.Go(func() { p.acceptBidi(p.upstream, p.client, p.closeClient) }) // Unidirectional streams in both directions. - go func() { defer wg.Done(); p.acceptUni(p.client, p.upstream, p.closeUpstream) }() - go func() { defer wg.Done(); p.acceptUni(p.upstream, p.client, p.closeClient) }() + wg.Go(func() { p.acceptUni(p.client, p.upstream, p.closeUpstream) }) + wg.Go(func() { p.acceptUni(p.upstream, p.client, p.closeClient) }) // Datagrams in both directions. - go func() { defer wg.Done(); p.pumpDatagrams(p.client, p.upstream, p.closeUpstream) }() - go func() { defer wg.Done(); p.pumpDatagrams(p.upstream, p.client, p.closeClient) }() + wg.Go(func() { p.pumpDatagrams(p.client, p.upstream, p.closeUpstream) }) + wg.Go(func() { p.pumpDatagrams(p.upstream, p.client, p.closeClient) }) wg.Wait() }