Skip to content

Commit

Permalink
Add timer for loopy writer to be closed
Browse files Browse the repository at this point in the history
  • Loading branch information
aranjans committed Jun 27, 2024
1 parent 5f5d4d2 commit 54fc2db
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 7 additions & 0 deletions internal/transport/http2_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,13 @@ func (t *http2Client) Close(err error) {
// Per HTTP/2 spec, a GOAWAY frame must be sent before closing the
// connection. See https://httpwg.org/specs/rfc7540.html#GOAWAY.
t.controlBuf.put(&goAway{code: http2.ErrCodeNo, debugData: []byte("client transport shutdown"), closeConn: err})
timer := time.NewTimer(5 * time.Minute)
t.logger.Infof("Waiting for the writerDone to be closed")
select {
case <-t.writerDone:
case <-timer.C:
t.logger.Infof("timeout waiting for the loopy writer to be closed")
}
<-t.writerDone
t.cancel()
t.conn.Close()
Expand Down
4 changes: 3 additions & 1 deletion internal/transport/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2661,7 +2661,7 @@ func TestConnectionError_Unwrap(t *testing.T) {
// error code and debug data.
func (s) TestClientSendsAGoAwayFrame(t *testing.T) {
// Create a server.
lis, err := net.Listen("tcp", "localhost:0")
lis, err := net.Listen("tcp", "localhost:3004")
if err != nil {
t.Fatalf("Error while listening: %v", err)
}
Expand Down Expand Up @@ -2735,6 +2735,8 @@ 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)
ct.Close(errors.New("manually closed by client"))
t.Logf("Closed the client connection")
select {
Expand Down

0 comments on commit 54fc2db

Please sign in to comment.