mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
pkg/transport: add 'IsClosedConnError'
Signed-off-by: Gyu-Ho Lee <gyuhox@gmail.com>
This commit is contained in:
parent
2dd361aba5
commit
8ce579aac9
@ -27,6 +27,7 @@ import (
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/coreos/etcd/pkg/tlsutil"
|
||||
@ -269,3 +270,12 @@ func ShallowCopyTLSConfig(cfg *tls.Config) *tls.Config {
|
||||
}
|
||||
return &ncfg
|
||||
}
|
||||
|
||||
// IsClosedConnError returns true if the error is from closing listener, cmux.
|
||||
// copied from golang.org/x/net/http2/http2.go
|
||||
func IsClosedConnError(err error) bool {
|
||||
// 'use of closed network connection' (Go <=1.8)
|
||||
// 'use of closed file or network connection' (Go >1.8, internal/poll.ErrClosing)
|
||||
// 'mux: listener closed' (cmux.ErrListenerClosed)
|
||||
return err != nil && strings.Contains(err.Error(), "closed")
|
||||
}
|
||||
|
@ -274,3 +274,15 @@ func TestNewListenerTLSInfoSelfCert(t *testing.T) {
|
||||
}
|
||||
testNewListenerTLSInfoAccept(t, tlsinfo)
|
||||
}
|
||||
|
||||
func TestIsClosedConnError(t *testing.T) {
|
||||
l, err := NewListener("testsocket", "unix", nil)
|
||||
if err != nil {
|
||||
t.Errorf("error listening on unix socket (%v)", err)
|
||||
}
|
||||
l.Close()
|
||||
_, err = l.Accept()
|
||||
if !IsClosedConnError(err) {
|
||||
t.Fatalf("expect true, got false (%v)", err)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user