Merge pull request #7862 from Gandi/bugfixes/segfault-registry-session

Fix SEGFAULT if dns resolv error
This commit is contained in:
Jessie Frazelle 2014-09-08 11:38:34 -07:00
commit 8440052689

View file

@ -154,6 +154,7 @@ func (r *Session) GetRemoteImageJSON(imgID, registry string, token []string) ([]
func (r *Session) GetRemoteImageLayer(imgID, registry string, token []string, imgSize int64) (io.ReadCloser, error) { func (r *Session) GetRemoteImageLayer(imgID, registry string, token []string, imgSize int64) (io.ReadCloser, error) {
var ( var (
retries = 5 retries = 5
statusCode = 0
client *http.Client client *http.Client
res *http.Response res *http.Response
imageURL = fmt.Sprintf("%simages/%s/layer", registry, imgID) imageURL = fmt.Sprintf("%simages/%s/layer", registry, imgID)
@ -165,14 +166,19 @@ func (r *Session) GetRemoteImageLayer(imgID, registry string, token []string, im
} }
setTokenAuth(req, token) setTokenAuth(req, token)
for i := 1; i <= retries; i++ { for i := 1; i <= retries; i++ {
statusCode = 0
res, client, err = r.doRequest(req) res, client, err = r.doRequest(req)
if err != nil { if err != nil {
log.Debugf("Error contacting registry: %s", err)
if res != nil {
if res.Body != nil { if res.Body != nil {
res.Body.Close() res.Body.Close()
} }
statusCode = res.StatusCode
}
if i == retries { if i == retries {
return nil, fmt.Errorf("Server error: Status %d while fetching image layer (%s)", return nil, fmt.Errorf("Server error: Status %d while fetching image layer (%s)",
res.StatusCode, imgID) statusCode, imgID)
} }
time.Sleep(time.Duration(i) * 5 * time.Second) time.Sleep(time.Duration(i) * 5 * time.Second)
continue continue