From 7de9ca519cc593f6051e3a764568081a7d1e7367 Mon Sep 17 00:00:00 2001 From: Kenfe-Mickael Laventure Date: Fri, 11 Aug 2017 10:20:31 -0700 Subject: [PATCH] Disable FailFast on client.IsServing() User of the client should associate a proper timeout with the context instead. Signed-off-by: Kenfe-Mickael Laventure --- client.go | 10 +++++++--- client_windows.go | 16 ---------------- client_unix.go => dialer.go | 24 +----------------------- dialer_unix.go | 32 ++++++++++++++++++++++++++++++++ dialer_windows.go | 29 +++++++++++++++++++++++++++++ 5 files changed, 69 insertions(+), 42 deletions(-) delete mode 100644 client_windows.go rename client_unix.go => dialer.go (66%) create mode 100644 dialer_unix.go create mode 100644 dialer_windows.go diff --git a/client.go b/client.go index ebe11efd6..d0a57199c 100644 --- a/client.go +++ b/client.go @@ -104,10 +104,14 @@ type Client struct { runtime string } -// IsServing returns true if the client can successfully connect to the containerd daemon -// and the healthcheck service returns the SERVING response +// IsServing returns true if the client can successfully connect to the +// containerd daemon and the healthcheck service returns the SERVING +// response. +// This call will block if a transient error is encountered during +// connection. A timeout can be set in the context to ensure it returns +// early. func (c *Client) IsServing(ctx context.Context) (bool, error) { - r, err := c.HealthService().Check(ctx, &grpc_health_v1.HealthCheckRequest{}) + r, err := c.HealthService().Check(ctx, &grpc_health_v1.HealthCheckRequest{}, grpc.FailFast(false)) if err != nil { return false, err } diff --git a/client_windows.go b/client_windows.go deleted file mode 100644 index 7f15adbd6..000000000 --- a/client_windows.go +++ /dev/null @@ -1,16 +0,0 @@ -package containerd - -import ( - "net" - "time" - - winio "github.com/Microsoft/go-winio" -) - -func Dialer(address string, timeout time.Duration) (net.Conn, error) { - return winio.DialPipe(address, &timeout) -} - -func DialAddress(address string) string { - return address -} diff --git a/client_unix.go b/dialer.go similarity index 66% rename from client_unix.go rename to dialer.go index e3715571f..0e54ebae1 100644 --- a/client_unix.go +++ b/dialer.go @@ -1,31 +1,13 @@ -// +build !windows - package containerd import ( - "fmt" "net" - "os" "strings" - "syscall" "time" "github.com/pkg/errors" ) -func isNoent(err error) bool { - if err != nil { - if nerr, ok := err.(*net.OpError); ok { - if serr, ok := nerr.Err.(*os.SyscallError); ok { - if serr.Err == syscall.ENOENT { - return true - } - } - } - } - return false -} - type dialResult struct { c net.Conn err error @@ -44,7 +26,7 @@ func Dialer(address string, timeout time.Duration) (net.Conn, error) { case <-stopC: return default: - c, err := net.DialTimeout("unix", address, timeout) + c, err := dialer(address, timeout) if isNoent(err) { <-time.After(10 * time.Millisecond) continue @@ -68,7 +50,3 @@ func Dialer(address string, timeout time.Duration) (net.Conn, error) { return nil, errors.Errorf("dial %s: no such file or directory", address) } } - -func DialAddress(address string) string { - return fmt.Sprintf("unix://%s", address) -} diff --git a/dialer_unix.go b/dialer_unix.go new file mode 100644 index 000000000..3c4689986 --- /dev/null +++ b/dialer_unix.go @@ -0,0 +1,32 @@ +// +build !windows + +package containerd + +import ( + "fmt" + "net" + "os" + "syscall" + "time" +) + +func isNoent(err error) bool { + if err != nil { + if nerr, ok := err.(*net.OpError); ok { + if serr, ok := nerr.Err.(*os.SyscallError); ok { + if serr.Err == syscall.ENOENT { + return true + } + } + } + } + return false +} + +func dialer(address string, timeout time.Duration) (net.Conn, error) { + return net.DialTimeout("unix", address, timeout) +} + +func DialAddress(address string) string { + return fmt.Sprintf("unix://%s", address) +} diff --git a/dialer_windows.go b/dialer_windows.go new file mode 100644 index 000000000..c91a32617 --- /dev/null +++ b/dialer_windows.go @@ -0,0 +1,29 @@ +package containerd + +import ( + "net" + "os" + "syscall" + "time" + + winio "github.com/Microsoft/go-winio" +) + +func isNoent(err error) bool { + if err != nil { + if oerr, ok := err.(*os.PathError); ok { + if oerr.Err == syscall.ENOENT { + return true + } + } + } + return false +} + +func dialer(address string, timeout time.Duration) (net.Conn, error) { + return winio.DialPipe(address, &timeout) +} + +func DialAddress(address string) string { + return address +}