Disable FailFast on client.IsServing()

User of the client should associate a proper timeout with the context
instead.

Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
This commit is contained in:
Kenfe-Mickael Laventure 2017-08-11 10:20:31 -07:00
parent a6be9f544d
commit 7de9ca519c
No known key found for this signature in database
GPG Key ID: 40CF16616B361216
5 changed files with 69 additions and 42 deletions

View File

@ -104,10 +104,14 @@ type Client struct {
runtime string runtime string
} }
// IsServing returns true if the client can successfully connect to the containerd daemon // IsServing returns true if the client can successfully connect to the
// and the healthcheck service returns the SERVING response // 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) { 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 { if err != nil {
return false, err return false, err
} }

View File

@ -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
}

View File

@ -1,31 +1,13 @@
// +build !windows
package containerd package containerd
import ( import (
"fmt"
"net" "net"
"os"
"strings" "strings"
"syscall"
"time" "time"
"github.com/pkg/errors" "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 { type dialResult struct {
c net.Conn c net.Conn
err error err error
@ -44,7 +26,7 @@ func Dialer(address string, timeout time.Duration) (net.Conn, error) {
case <-stopC: case <-stopC:
return return
default: default:
c, err := net.DialTimeout("unix", address, timeout) c, err := dialer(address, timeout)
if isNoent(err) { if isNoent(err) {
<-time.After(10 * time.Millisecond) <-time.After(10 * time.Millisecond)
continue 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) return nil, errors.Errorf("dial %s: no such file or directory", address)
} }
} }
func DialAddress(address string) string {
return fmt.Sprintf("unix://%s", address)
}

32
dialer_unix.go Normal file
View File

@ -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)
}

29
dialer_windows.go Normal file
View File

@ -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
}