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.
This commit is contained in:
tomholford 2026-05-05 18:24:34 -07:00
parent 04dff423b3
commit 4899e53c2d

View file

@ -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()
}