Skip to content

Commit 1dccf7b

Browse files
committed
net/http: make sure HTTP/3 transport QUIC are closed after tests
Close transport QUIC endpoints synchronously in a t.Cleanup, so that they are not detected as goroutine leaks and cause TestMain failures. For #78737 For #70914 Change-Id: I6dfc29b8d6926bd420608e03342455f36a6a6964 Reviewed-on: https://go-review.googlesource.com/c/go/+/768081 Reviewed-by: Damien Neil <dneil@google.com> LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Nicholas Husin <husin@google.com>
1 parent 8073323 commit 1dccf7b

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/net/http/clientserver_test.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,29 @@ func newClientServerTest(t testing.TB, mode testMode, h Handler, opts ...any) *c
309309
cst.tr.Protocols = p
310310
}
311311
if mode == http3Mode {
312-
registerHTTP3Transport(cst.tr)
312+
endpointCh := registerHTTP3Transport(cst.tr)
313+
testDoneCh := make(chan any)
314+
var wg sync.WaitGroup
315+
t.Cleanup(func() {
316+
close(testDoneCh)
317+
wg.Wait()
318+
})
319+
wg.Go(func() {
320+
for {
321+
select {
322+
case e := <-endpointCh:
323+
t.Cleanup(func() {
324+
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
325+
defer cancel()
326+
if e != nil {
327+
e.Close(ctx)
328+
}
329+
})
330+
case <-testDoneCh:
331+
return
332+
}
333+
}
334+
})
313335
}
314336

315337
t.Cleanup(func() {

0 commit comments

Comments
 (0)