]> Cypherpunks.ru repositories - gostls13.git/commitdiff
crypto/tls: replace errClosed with net.ErrClosed
authorAinar Garipov <gugl.zadolbal@gmail.com>
Wed, 23 Sep 2020 18:15:01 +0000 (21:15 +0300)
committerKatie Hockman <katie@golang.org>
Thu, 24 Sep 2020 15:48:24 +0000 (15:48 +0000)
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 <katie@golang.org>
Trust: Katie Hockman <katie@golang.org>
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Katie Hockman <katie@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>

src/crypto/tls/conn.go
src/crypto/tls/tls_test.go

index edcfecf81d77c63d9b3a14eee29a85bf0fed3324..5dff76c9889a4085b0a5fa72d4c83941cdc51302 100644 (file)
@@ -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
index 198423414b9a871be38b4e4a00323733d440422f..334bfc411a7d1b819746b6fb2fcff2d5ef70a64c 100644 (file)
@@ -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)
        }
 }