@@ -6374,87 +6374,3 @@ func (c *blockReadConn) Read(b []byte) (n int, err error) {
6374
6374
<- c .blockc
6375
6375
return c .Conn .Read (b )
6376
6376
}
6377
-
6378
- func TestTransportReuseAfterError (t * testing.T ) {
6379
- serverReqc := make (chan struct {}, 3 )
6380
- st := newServerTester (t , func (w http.ResponseWriter , r * http.Request ) {
6381
- serverReqc <- struct {}{}
6382
- }, optOnlyServer )
6383
- defer st .Close ()
6384
-
6385
- var (
6386
- unblockOnce sync.Once
6387
- blockc = make (chan struct {})
6388
- connCountMu sync.Mutex
6389
- connCount int
6390
- )
6391
- tr := & Transport {
6392
- TLSClientConfig : tlsConfigInsecure ,
6393
- DialTLS : func (network , addr string , cfg * tls.Config ) (net.Conn , error ) {
6394
- // The first connection dialed will block on reads until blockc is closed.
6395
- connCountMu .Lock ()
6396
- defer connCountMu .Unlock ()
6397
- connCount ++
6398
- conn , err := tls .Dial (network , addr , cfg )
6399
- if err != nil {
6400
- return nil , err
6401
- }
6402
- if connCount == 1 {
6403
- return & blockReadConn {
6404
- Conn : conn ,
6405
- blockc : blockc ,
6406
- }, nil
6407
- }
6408
- return conn , nil
6409
- },
6410
- }
6411
- defer tr .CloseIdleConnections ()
6412
- defer unblockOnce .Do (func () {
6413
- // Ensure that reads on blockc are unblocked if we return early.
6414
- close (blockc )
6415
- })
6416
-
6417
- req , _ := http .NewRequest ("GET" , st .ts .URL , nil )
6418
-
6419
- // Request 1 is made on conn 1.
6420
- // Reading the response will block.
6421
- // Wait until the server receives the request, and continue.
6422
- req1c := make (chan struct {})
6423
- go func () {
6424
- defer close (req1c )
6425
- res1 , err := tr .RoundTrip (req .Clone (context .Background ()))
6426
- if err != nil {
6427
- t .Errorf ("request 1: %v" , err )
6428
- } else {
6429
- res1 .Body .Close ()
6430
- }
6431
- }()
6432
- <- serverReqc
6433
-
6434
- // Request 2 is also made on conn 1.
6435
- // Reading the response will block.
6436
- // The request is canceled once the server receives it.
6437
- // Conn 1 should now be flagged as unfit for reuse.
6438
- req2Ctx , cancel := context .WithCancel (context .Background ())
6439
- go func () {
6440
- <- serverReqc
6441
- cancel ()
6442
- }()
6443
- _ , err := tr .RoundTrip (req .Clone (req2Ctx ))
6444
- if err == nil {
6445
- t .Errorf ("request 2 unexpectedly succeeded (want cancel)" )
6446
- }
6447
-
6448
- // Request 3 is made on a new conn, and succeeds.
6449
- res3 , err := tr .RoundTrip (req .Clone (context .Background ()))
6450
- if err != nil {
6451
- t .Fatalf ("request 3: %v" , err )
6452
- }
6453
- res3 .Body .Close ()
6454
-
6455
- // Unblock conn 1, and verify that request 1 completes.
6456
- unblockOnce .Do (func () {
6457
- close (blockc )
6458
- })
6459
- <- req1c
6460
- }
0 commit comments