Skip to content

Commit dd4570e

Browse files
committed
Revert an upstream Go change that broke us.
See golang/go#60818 Updates tailscale/corp#12296 Signed-off-by: Brad Fitzpatrick <brad@danga.com>
1 parent f5464dd commit dd4570e

File tree

2 files changed

+5
-89
lines changed

2 files changed

+5
-89
lines changed

http2/transport.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -1266,11 +1266,11 @@ func (cc *ClientConn) RoundTrip(req *http.Request) (*http.Response, error) {
12661266
return res, nil
12671267
}
12681268

1269-
cancelRequest := func(cs *clientStream, err error) error {
1269+
cancelRequest := func(cs *clientStream, markDoNotReuse bool, err error) error {
12701270
cs.cc.mu.Lock()
12711271
cs.abortStreamLocked(err)
12721272
bodyClosed := cs.reqBodyClosed
1273-
if cs.ID != 0 {
1273+
if markDoNotReuse && cs.ID != 0 {
12741274
// This request may have failed because of a problem with the connection,
12751275
// or for some unrelated reason. (For example, the user might have canceled
12761276
// the request without waiting for a response.) Mark the connection as
@@ -1318,12 +1318,12 @@ func (cc *ClientConn) RoundTrip(req *http.Request) (*http.Response, error) {
13181318
return handleResponseHeaders()
13191319
default:
13201320
waitDone()
1321-
return nil, cancelRequest(cs, cs.abortErr)
1321+
return nil, cancelRequest(cs, true, cs.abortErr)
13221322
}
13231323
case <-ctx.Done():
1324-
return nil, cancelRequest(cs, ctx.Err())
1324+
return nil, cancelRequest(cs, false, ctx.Err())
13251325
case <-cs.reqCancel:
1326-
return nil, cancelRequest(cs, errRequestCanceled)
1326+
return nil, cancelRequest(cs, false, errRequestCanceled)
13271327
}
13281328
}
13291329
}

http2/transport_test.go

-84
Original file line numberDiff line numberDiff line change
@@ -6374,87 +6374,3 @@ func (c *blockReadConn) Read(b []byte) (n int, err error) {
63746374
<-c.blockc
63756375
return c.Conn.Read(b)
63766376
}
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

Comments
 (0)