зеркало из https://github.com/docker/engine-api.git
Merge pull request #349 from tamird/docker-cannot-connect-context
client: only return ErrConnectionFailed on fatal network errors
This commit is contained in:
Коммит
fc564829f6
|
@ -6,6 +6,7 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
@ -105,7 +106,7 @@ func (cli *Client) sendClientRequest(ctx context.Context, method, path string, q
|
|||
|
||||
resp, err := cancellable.Do(ctx, cli.transport, req)
|
||||
if err != nil {
|
||||
if isTimeout(err) || strings.Contains(err.Error(), "connection refused") || strings.Contains(err.Error(), "dial unix") {
|
||||
if err, ok := err.(net.Error); ok && !err.Temporary() {
|
||||
return serverResp, ErrConnectionFailed
|
||||
}
|
||||
|
||||
|
@ -199,16 +200,3 @@ 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()
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче