Skip to content

Commit

Permalink
Set http write deadline for client close() method
Browse files Browse the repository at this point in the history
  • Loading branch information
aranjans committed Jun 27, 2024
1 parent 98e5dee commit 533b620
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/transport/http2_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,7 @@ 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 Expand Up @@ -1016,7 +1017,6 @@ func (t *http2Client) Close(err error) {
// Append info about previous goaways if there were any, since this may be important
// for understanding the root cause for this connection to be closed.
_, goAwayDebugMessage := t.GetGoAwayReason()

var st *status.Status
if len(goAwayDebugMessage) > 0 {
st = status.Newf(codes.Unavailable, "closing transport due to: %v, received prior goaway: %v", err, goAwayDebugMessage)
Expand Down
2 changes: 2 additions & 0 deletions internal/transport/transport_test.go
Original file line number Diff line number Diff line change
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 533b620

Please sign in to comment.