From 8e8bfb697fbc948494d67428c4953605cc89b6f4 Mon Sep 17 00:00:00 2001 From: Ainar Garipov Date: Wed, 23 Sep 2020 21:15:01 +0300 Subject: [PATCH] crypto/tls: replace errClosed with net.ErrClosed CL 250357 exported net.ErrClosed to allow more reliable detection of closed network connection errors. Use that error in crypto/tls as well. The error message is changed from "tls: use of closed connection" to "use of closed network connection", so the code that detected such errors by looking for that text in the error message will need to be updated to use errors.Is(err, net.ErrClosed) instead. Fixes #41066 Change-Id: Ic05c0ed6a4f57af2a0302d53b00851a59200be2e Reviewed-on: https://go-review.googlesource.com/c/go/+/256897 Reviewed-by: Katie Hockman Trust: Katie Hockman Trust: Ian Lance Taylor Run-TryBot: Katie Hockman TryBot-Result: Go Bot --- src/crypto/tls/conn.go | 5 ++--- src/crypto/tls/tls_test.go | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/crypto/tls/conn.go b/src/crypto/tls/conn.go index edcfecf81d..5dff76c988 100644 --- a/src/crypto/tls/conn.go +++ b/src/crypto/tls/conn.go @@ -1070,7 +1070,6 @@ func (c *Conn) readHandshake() (interface{}, error) { } var ( - errClosed = errors.New("tls: use of closed connection") errShutdown = errors.New("tls: protocol is shutdown") ) @@ -1080,7 +1079,7 @@ func (c *Conn) Write(b []byte) (int, error) { for { x := atomic.LoadInt32(&c.activeCall) if x&1 != 0 { - return 0, errClosed + return 0, net.ErrClosed } if atomic.CompareAndSwapInt32(&c.activeCall, x, x+2) { break @@ -1285,7 +1284,7 @@ func (c *Conn) Close() error { for { x = atomic.LoadInt32(&c.activeCall) if x&1 != 0 { - return errClosed + return net.ErrClosed } if atomic.CompareAndSwapInt32(&c.activeCall, x, x|1) { break diff --git a/src/crypto/tls/tls_test.go b/src/crypto/tls/tls_test.go index 198423414b..334bfc411a 100644 --- a/src/crypto/tls/tls_test.go +++ b/src/crypto/tls/tls_test.go @@ -569,8 +569,8 @@ func TestConnCloseBreakingWrite(t *testing.T) { } <-closeReturned - if err := tconn.Close(); err != errClosed { - t.Errorf("Close error = %v; want errClosed", err) + if err := tconn.Close(); err != net.ErrClosed { + t.Errorf("Close error = %v; want net.ErrClosed", err) } } -- 2.50.0