diff --git a/api/client/lib/request.go b/api/client/lib/request.go index db3e5065a2..67984d116b 100644 --- a/api/client/lib/request.go +++ b/api/client/lib/request.go @@ -9,8 +9,6 @@ import ( "net/http" "net/url" "strings" - - "github.com/docker/docker/utils" ) // serverResponse is a wrapper for http API responses. @@ -96,7 +94,7 @@ func (cli *Client) sendClientRequest(method, path string, query url.Values, body } if err != nil { - if utils.IsTimeout(err) || strings.Contains(err.Error(), "connection refused") || strings.Contains(err.Error(), "dial unix") { + if isTimeout(err) || strings.Contains(err.Error(), "connection refused") || strings.Contains(err.Error(), "dial unix") { return serverResp, ErrConnectionFailed } @@ -163,3 +161,16 @@ func ensureReaderClosed(response *serverResponse) { response.body.Close() } } + +func isTimeout(err error) bool { + type timeout interface { + Timeout() bool + } + e := err + switch urlErr := err.(type) { + case *url.Error: + e = urlErr.Err + } + t, ok := e.(timeout) + return ok && t.Timeout() +} diff --git a/registry/session.go b/registry/session.go index 25bffc7fb6..4be9b7afce 100644 --- a/registry/session.go +++ b/registry/session.go @@ -25,7 +25,6 @@ import ( "github.com/docker/docker/pkg/ioutils" "github.com/docker/docker/pkg/stringid" "github.com/docker/docker/pkg/tarsum" - "github.com/docker/docker/utils" ) var ( @@ -420,7 +419,7 @@ func (r *Session) GetRepositoryData(remote reference.Named) (*RepositoryData, er // and return a non-obtuse error message for users // "Get https://index.docker.io/v1/repositories/library/busybox/images: i/o timeout" // was a top search on the docker user forum - if utils.IsTimeout(err) { + if isTimeout(err) { return nil, fmt.Errorf("Network timed out while trying to connect to %s. You may want to check your internet connection or if you are behind a proxy.", repositoryTarget) } return nil, fmt.Errorf("Error while pulling image: %v", err) @@ -754,3 +753,16 @@ func (r *Session) GetAuthConfig(withPasswd bool) *types.AuthConfig { Email: r.authConfig.Email, } } + +func isTimeout(err error) bool { + type timeout interface { + Timeout() bool + } + e := err + switch urlErr := err.(type) { + case *url.Error: + e = urlErr.Err + } + t, ok := e.(timeout) + return ok && t.Timeout() +} diff --git a/utils/timeout.go b/utils/timeout.go deleted file mode 100644 index 85d2665c60..0000000000 --- a/utils/timeout.go +++ /dev/null @@ -1,21 +0,0 @@ -package utils - -import ( - "net" - "net/url" -) - -// IsTimeout takes an error returned from (generally) the http package and determines if it is a timeout error. -func IsTimeout(err error) bool { - switch e := err.(type) { - case net.Error: - return e.Timeout() - case *url.Error: - if t, ok := e.Err.(net.Error); ok { - return t.Timeout() - } - return false - default: - return false - } -}