Per registry.doRequest, res and client might be nil in case of error
For example, dns resolution errors, /etc/docker/certs.d perms, failed
loading of x509 cert ...
This will make res.StatusCode and res.Body SEGFAULT.
Signed-off-by: Arthur Gautier <baloo@gandi.net>
| ... | ... |
@@ -153,10 +153,11 @@ func (r *Session) GetRemoteImageJSON(imgID, registry string, token []string) ([] |
| 153 | 153 |
|
| 154 | 154 |
func (r *Session) GetRemoteImageLayer(imgID, registry string, token []string, imgSize int64) (io.ReadCloser, error) {
|
| 155 | 155 |
var ( |
| 156 |
- retries = 5 |
|
| 157 |
- client *http.Client |
|
| 158 |
- res *http.Response |
|
| 159 |
- imageURL = fmt.Sprintf("%simages/%s/layer", registry, imgID)
|
|
| 156 |
+ retries = 5 |
|
| 157 |
+ statusCode = 0 |
|
| 158 |
+ client *http.Client |
|
| 159 |
+ res *http.Response |
|
| 160 |
+ imageURL = fmt.Sprintf("%simages/%s/layer", registry, imgID)
|
|
| 160 | 161 |
) |
| 161 | 162 |
|
| 162 | 163 |
req, err := r.reqFactory.NewRequest("GET", imageURL, nil)
|
| ... | ... |
@@ -165,14 +166,19 @@ func (r *Session) GetRemoteImageLayer(imgID, registry string, token []string, im |
| 165 | 165 |
} |
| 166 | 166 |
setTokenAuth(req, token) |
| 167 | 167 |
for i := 1; i <= retries; i++ {
|
| 168 |
+ statusCode = 0 |
|
| 168 | 169 |
res, client, err = r.doRequest(req) |
| 169 | 170 |
if err != nil {
|
| 170 |
- if res.Body != nil {
|
|
| 171 |
- res.Body.Close() |
|
| 171 |
+ log.Debugf("Error contacting registry: %s", err)
|
|
| 172 |
+ if res != nil {
|
|
| 173 |
+ if res.Body != nil {
|
|
| 174 |
+ res.Body.Close() |
|
| 175 |
+ } |
|
| 176 |
+ statusCode = res.StatusCode |
|
| 172 | 177 |
} |
| 173 | 178 |
if i == retries {
|
| 174 | 179 |
return nil, fmt.Errorf("Server error: Status %d while fetching image layer (%s)",
|
| 175 |
- res.StatusCode, imgID) |
|
| 180 |
+ statusCode, imgID) |
|
| 176 | 181 |
} |
| 177 | 182 |
time.Sleep(time.Duration(i) * 5 * time.Second) |
| 178 | 183 |
continue |