Skip to content

Commit

Permalink
repro
Browse files Browse the repository at this point in the history
  • Loading branch information
aranjans committed Jun 27, 2024
1 parent 533b620 commit 7247c7d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
1 change: 0 additions & 1 deletion internal/transport/http2_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,6 @@ func (t *http2Client) closeStream(s *Stream, err error, rst bool, rstCode http2.
// only once on a transport. Once it is called, the transport should not be
// accessed anymore.
func (t *http2Client) Close(err error) {
t.conn.SetWriteDeadline(time.Now().Add(time.Second * 20))
t.mu.Lock()
// Make sure we only close once.
if t.state == closing {
Expand Down
33 changes: 29 additions & 4 deletions internal/transport/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2656,6 +2656,24 @@ func TestConnectionError_Unwrap(t *testing.T) {
}
}

type hangingConn struct {
net.Conn
}

func (hc *hangingConn) Read(b []byte) (n int, err error) {
n, err = hc.Conn.Read(b)
fmt.Printf("Got read data as : %v, %v\n", string(b), n)
if n == 0 { // ErrorCode 0x0 for goAwayFrame, checkout http2Client.Close() where we are putting the goAwayFrame in control buffer.
time.Sleep(time.Hour)
}
return n, err
}

func (hc *hangingConn) Write(b []byte) (n int, err error) {
n, err = hc.Conn.Write(b)
return n, err
}

// Test that in the event of a graceful client transport shutdown, i.e.,
// clientTransport.Close(), client sends a goaway to the server with the correct
// error code and debug data.
Expand Down Expand Up @@ -2725,7 +2743,15 @@ func (s) TestClientSendsAGoAwayFrame(t *testing.T) {
}
}()

ct, err := NewClientTransport(ctx, context.Background(), resolver.Address{Addr: lis.Addr().String()}, ConnectOptions{}, func(GoAwayReason) {})
ct, err := NewClientTransport(ctx, context.Background(), resolver.Address{Addr: lis.Addr().String()}, ConnectOptions{
Dialer: func(ctx context.Context, s2 string) (net.Conn, error) {
conn, err := net.Dial("tcp", lis.Addr().String())
if err != nil {
return nil, err
}
return &hangingConn{Conn: conn}, nil
},
}, func(GoAwayReason) {})
if err != nil {
t.Fatalf("Error while creating client transport: %v", err)
}
Expand All @@ -2735,10 +2761,9 @@ func (s) TestClientSendsAGoAwayFrame(t *testing.T) {
}
// Wait until server receives the headers and settings frame as part of greet.
<-greetDone
t.Logf("Adding 25s delay post the RPC call and before client conn close.")
time.Sleep(25 * time.Second)
t.Logf("Adding 25s delay post the RPC call and before client conn close. timestamp: %v", time.Now())
ct.Close(errors.New("manually closed by client"))
t.Logf("Closed the client connection")
t.Logf("Closed the client connection, timestamp: %v", time.Now())
select {
case err := <-errorCh:
if err != nil {
Expand Down

0 comments on commit 7247c7d

Please sign in to comment.