Skip to content

Commit 8e8bfb6

Browse files
ainar-gkatiehockman
authored andcommitted
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 <[email protected]> Trust: Katie Hockman <[email protected]> Trust: Ian Lance Taylor <[email protected]> Run-TryBot: Katie Hockman <[email protected]> TryBot-Result: Go Bot <[email protected]>
1 parent 9e073b5 commit 8e8bfb6

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

src/crypto/tls/conn.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,6 @@ func (c *Conn) readHandshake() (interface{}, error) {
10701070
}
10711071

10721072
var (
1073-
errClosed = errors.New("tls: use of closed connection")
10741073
errShutdown = errors.New("tls: protocol is shutdown")
10751074
)
10761075

@@ -1080,7 +1079,7 @@ func (c *Conn) Write(b []byte) (int, error) {
10801079
for {
10811080
x := atomic.LoadInt32(&c.activeCall)
10821081
if x&1 != 0 {
1083-
return 0, errClosed
1082+
return 0, net.ErrClosed
10841083
}
10851084
if atomic.CompareAndSwapInt32(&c.activeCall, x, x+2) {
10861085
break
@@ -1285,7 +1284,7 @@ func (c *Conn) Close() error {
12851284
for {
12861285
x = atomic.LoadInt32(&c.activeCall)
12871286
if x&1 != 0 {
1288-
return errClosed
1287+
return net.ErrClosed
12891288
}
12901289
if atomic.CompareAndSwapInt32(&c.activeCall, x, x|1) {
12911290
break

src/crypto/tls/tls_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,8 +569,8 @@ func TestConnCloseBreakingWrite(t *testing.T) {
569569
}
570570

571571
<-closeReturned
572-
if err := tconn.Close(); err != errClosed {
573-
t.Errorf("Close error = %v; want errClosed", err)
572+
if err := tconn.Close(); err != net.ErrClosed {
573+
t.Errorf("Close error = %v; want net.ErrClosed", err)
574574
}
575575
}
576576

0 commit comments

Comments
 (0)