Skip to content

Commit

Permalink
[better_conn_close_error] c1
Browse files Browse the repository at this point in the history
  • Loading branch information
menghanl committed May 25, 2021
1 parent f3e0c6b commit 9602024
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/transport/http2_client.go
Expand Up @@ -59,7 +59,6 @@ type http2Client struct {
ctx context.Context
cancel context.CancelFunc
ctxDone <-chan struct{} // Cache the ctx.Done() chan.
closeErr error // Reason the transport is closed. Only set if ctx is canceled.
userAgent string
md metadata.MD
conn net.Conn // underlying communication channel
Expand Down Expand Up @@ -110,6 +109,7 @@ type http2Client struct {

mu sync.Mutex // guard the following variables
state transportState
closeErr error // Reason the transport is closed. Only set if ctx is canceled.
activeStreams map[uint32]*Stream
// prevGoAway ID records the Last-Stream-ID in the previous GOAway frame.
prevGoAwayID uint32
Expand Down
6 changes: 6 additions & 0 deletions internal/transport/transport_test.go
Expand Up @@ -781,6 +781,12 @@ func (s) TestGracefulClose(t *testing.T) {
defer wg.Done()
str, err := ct.NewStream(ctx, &CallHdr{})
if err != nil {
// The NewStream calls race with closing of the transport (after
// the last stream is closed).
// - if it is after the transport is closed (case <-ct.ctxDone),
// we don't care about the error.
// - if it's before the transport is closed (default), we want
// the NewStream call to succeed.
select {
case <-ct.ctxDone:
default:
Expand Down

0 comments on commit 9602024

Please sign in to comment.