mirror of
https://github.com/golang/go
synced 2024-11-23 07:00:05 -07:00
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 <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>
This commit is contained in:
parent
9e073b504f
commit
8e8bfb697f
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user