@@ -3562,6 +3562,38 @@ func TestTransportCloseIdleConnsThenReturn(t *testing.T) {
3562
3562
wantIdle ("after final put" , 1 )
3563
3563
}
3564
3564
3565
+ // Test for issue 34282
3566
+ // Ensure that getConn doesn't call the GotConn trace hook on a HTTP/2 idle conn
3567
+ func TestTransportTraceGotConnH2IdleConns (t * testing.T ) {
3568
+ tr := & Transport {}
3569
+ wantIdle := func (when string , n int ) bool {
3570
+ got := tr .IdleConnCountForTesting ("https" , "example.com:443" ) // key used by PutIdleTestConnH2
3571
+ if got == n {
3572
+ return true
3573
+ }
3574
+ t .Errorf ("%s: idle conns = %d; want %d" , when , got , n )
3575
+ return false
3576
+ }
3577
+ wantIdle ("start" , 0 )
3578
+ alt := funcRoundTripper (func () {})
3579
+ if ! tr .PutIdleTestConnH2 ("https" , "example.com:443" , alt ) {
3580
+ t .Fatal ("put failed" )
3581
+ }
3582
+ wantIdle ("after put" , 1 )
3583
+ ctx := httptrace .WithClientTrace (context .Background (), & httptrace.ClientTrace {
3584
+ GotConn : func (httptrace.GotConnInfo ) {
3585
+ // tr.getConn should leave it for the HTTP/2 alt to call GotConn.
3586
+ t .Error ("GotConn called" )
3587
+ },
3588
+ })
3589
+ req , _ := NewRequestWithContext (ctx , MethodGet , "https://example.com" , nil )
3590
+ _ , err := tr .RoundTrip (req )
3591
+ if err != errFakeRoundTrip {
3592
+ t .Errorf ("got error: %v; want %q" , err , errFakeRoundTrip )
3593
+ }
3594
+ wantIdle ("after round trip" , 1 )
3595
+ }
3596
+
3565
3597
// This tests that an client requesting a content range won't also
3566
3598
// implicitly ask for gzip support. If they want that, they need to do it
3567
3599
// on their own.
0 commit comments