forked from TrueCloudLab/distribution
Merge pull request #1406 from dotcloud/1363-reduce_timeout-fix
Reduce connect and read timeout when pinging the registry (fixes issue #1363)
This commit is contained in:
commit
f1ead19f3f
1 changed files with 15 additions and 1 deletions
|
@ -9,12 +9,14 @@ import (
|
||||||
"github.com/dotcloud/docker/utils"
|
"github.com/dotcloud/docker/utils"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/cookiejar"
|
"net/http/cookiejar"
|
||||||
"net/url"
|
"net/url"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -28,7 +30,19 @@ func pingRegistryEndpoint(endpoint string) error {
|
||||||
// (and we never want to fallback to http in case of error)
|
// (and we never want to fallback to http in case of error)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
resp, err := http.Get(endpoint + "_ping")
|
httpDial := func(proto string, addr string) (net.Conn, error) {
|
||||||
|
// Set the connect timeout to 5 seconds
|
||||||
|
conn, err := net.DialTimeout(proto, addr, time.Duration(5)*time.Second)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
// Set the recv timeout to 10 seconds
|
||||||
|
conn.SetDeadline(time.Now().Add(time.Duration(10) * time.Second))
|
||||||
|
return conn, nil
|
||||||
|
}
|
||||||
|
httpTransport := &http.Transport{Dial: httpDial}
|
||||||
|
client := &http.Client{Transport: httpTransport}
|
||||||
|
resp, err := client.Get(endpoint + "_ping")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue