diff --git a/test/end2end_test.go b/test/end2end_test.go index f6099d97..3b38e00a 100644 --- a/test/end2end_test.go +++ b/test/end2end_test.go @@ -2219,8 +2219,8 @@ func testClientRequestBodyError_Cancel(t *testing.T, e env) { te.withServerTester(func(st *serverTester) { st.writeHeadersGRPC(1, "/grpc.testing.TestService/UnaryCall") // Say we have 5 bytes coming, but cancel it instead. - st.writeData(1, false, []byte{0, 0, 0, 0, 5}) st.writeRSTStream(1, http2.ErrCodeCancel) + st.writeData(1, false, []byte{0, 0, 0, 0, 5}) // Verify we didn't a call yet. select { diff --git a/transport/transport.go b/transport/transport.go index 0aebf598..10b4a2e2 100644 --- a/transport/transport.go +++ b/transport/transport.go @@ -559,12 +559,6 @@ func wait(ctx context.Context, done, goAway, closing <-chan struct{}, proceed <- case <-closing: return 0, ErrConnClosing case i := <-proceed: - // User cancellation has precedence. - select { - case <-ctx.Done(): - return 0, ContextErr(ctx.Err()) - default: - } return i, nil } } diff --git a/transport/transport_test.go b/transport/transport_test.go index a08376d3..e57d8e4a 100644 --- a/transport/transport_test.go +++ b/transport/transport_test.go @@ -111,20 +111,28 @@ func (h *testStreamHandler) handleStreamMisbehave(t *testing.T, s *Stream) { if !ok { t.Fatalf("Failed to convert %v to *http2Server", s.ServerTransport()) } - size := 1 - if s.Method() == "foo.MaxFrame" { - size = http2MaxFrameLen - } - // Drain the client side stream flow control window. var sent int - for sent <= initialWindowSize { + p := make([]byte, http2MaxFrameLen) + for sent < initialWindowSize { <-conn.writableChan - if err := conn.framer.writeData(true, s.id, false, make([]byte, size)); err != nil { + n := initialWindowSize - sent + // The last message may be smaller than http2MaxFrameLen + if n <= http2MaxFrameLen { + if s.Method() == "foo.Connection" { + // Violate connection level flow control window of client but do not + // violate any stream level windows. + p = make([]byte, n) + } else { + // Violate stream level flow control window of client. + p = make([]byte, n+1) + } + } + if err := conn.framer.writeData(true, s.id, false, p); err != nil { conn.writableChan <- 0 break } conn.writableChan <- 0 - sent += size + sent += len(p) } } @@ -660,7 +668,7 @@ func TestClientWithMisbehavedServer(t *testing.T) { server, ct := setUp(t, 0, math.MaxUint32, misbehaved) callHdr := &CallHdr{ Host: "localhost", - Method: "foo", + Method: "foo.Stream", } conn, ok := ct.(*http2Client) if !ok { @@ -671,7 +679,8 @@ func TestClientWithMisbehavedServer(t *testing.T) { if err != nil { t.Fatalf("Failed to open stream: %v", err) } - if err := ct.Write(s, expectedRequest, &Options{Last: true, Delay: false}); err != nil { + d := make([]byte, 1) + if err := ct.Write(s, d, &Options{Last: true, Delay: false}); err != nil { t.Fatalf("Failed to write: %v", err) } // Read without window update. @@ -693,18 +702,15 @@ func TestClientWithMisbehavedServer(t *testing.T) { } // Test the logic for the violation of the connection flow control window size restriction. // - // Generate enough streams to drain the connection window. - callHdr = &CallHdr{ - Host: "localhost", - Method: "foo.MaxFrame", - } - // Make the server flood the traffic to violate flow control window size of the connection. - for { + // Generate enough streams to drain the connection window. Make the server flood the traffic + // to violate flow control window size of the connection. + callHdr.Method = "foo.Connection" + for i := 0; i < int(initialConnWindowSize/initialWindowSize+10); i++ { s, err := ct.NewStream(context.Background(), callHdr) if err != nil { break } - if err := ct.Write(s, expectedRequest, &Options{Last: true, Delay: false}); err != nil { + if err := ct.Write(s, d, &Options{Last: true, Delay: false}); err != nil { break } } @@ -733,7 +739,7 @@ func TestEncodingRequiredStatus(t *testing.T) { Last: true, Delay: false, } - if err := ct.Write(s, expectedRequest, &opts); err != nil || err == io.EOF { + if err := ct.Write(s, expectedRequest, &opts); err != nil && err != io.EOF { t.Fatalf("Failed to write the request: %v", err) } p := make([]byte, http2MaxFrameLen)