From 293b2f9fa8e1a38bd54c63bae18251bfe2c17b07 Mon Sep 17 00:00:00 2001 From: iamqizhao Date: Thu, 21 Apr 2016 13:42:59 -0700 Subject: [PATCH] Close errorChan even when there is no pending I/O --- test/end2end_test.go | 18 ++++++++++++++++++ transport/http2_client.go | 3 +++ 2 files changed, 21 insertions(+) diff --git a/test/end2end_test.go b/test/end2end_test.go index 09b786d3..8bd84f49 100644 --- a/test/end2end_test.go +++ b/test/end2end_test.go @@ -746,6 +746,24 @@ func testHealthCheckServingStatus(t *testing.T, e env) { } +func TestErrorChanNoIO(t *testing.T) { + defer leakCheck(t)() + for _, e := range listTestEnv() { + testErrorChanNoIO(t, e) + } +} + +func testErrorChanNoIO(t *testing.T, e env) { + te := newTest(t, e) + te.startServer() + defer te.tearDown() + + tc := testpb.NewTestServiceClient(te.clientConn()) + if _, err := tc.FullDuplexCall(context.Background()); err != nil { + t.Fatalf("%v.FullDuplexCall(_) = _, %v, want ", tc, err) + } +} + func TestEmptyUnaryWithUserAgent(t *testing.T) { defer leakCheck(t)() for _, e := range listTestEnv() { diff --git a/transport/http2_client.go b/transport/http2_client.go index 258695b2..63d2c5e0 100644 --- a/transport/http2_client.go +++ b/transport/http2_client.go @@ -427,6 +427,9 @@ func (t *http2Client) CloseStream(s *Stream, err error) { // accessed any more. func (t *http2Client) Close() (err error) { t.mu.Lock() + if t.state == reachable { + close(t.errorChan) + } if t.state == closing { t.mu.Unlock() return errors.New("transport: Close() was already called")