From fc340ec9667b9adb3df1ff6599b7bbc64b6838b7 Mon Sep 17 00:00:00 2001 From: Sam Alba Date: Mon, 3 Jun 2013 12:14:57 -0700 Subject: [PATCH 1/3] Fixed missing Body.Close when doing some HTTP requests. It should improve some request issues. --- docs/registry.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/registry.go b/docs/registry.go index 36b01d64..d9f53ee9 100644 --- a/docs/registry.go +++ b/docs/registry.go @@ -64,6 +64,9 @@ func (r *Registry) LookupRemoteImage(imgId, registry string, authConfig *auth.Au } req.SetBasicAuth(authConfig.Username, authConfig.Password) res, err := rt.RoundTrip(req) + if err == nil { + defer res.Body.Close() + } return err == nil && res.StatusCode == 307 } @@ -152,7 +155,9 @@ func (r *Registry) GetRemoteTags(registries []string, repository string, token [ } req.Header.Set("Authorization", "Token "+strings.Join(token, ", ")) res, err := r.client.Do(req) - defer res.Body.Close() + if err == nil { + defer res.Body.Close() + } utils.Debugf("Got status code %d from %s", res.StatusCode, endpoint) if err != nil || (res.StatusCode != 200 && res.StatusCode != 404) { continue From 6189c3cb0b517586ddab9db5a16bbed039b68a83 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Mon, 3 Jun 2013 12:20:52 -0700 Subject: [PATCH 2/3] Minor changes in registry.go --- docs/registry.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/docs/registry.go b/docs/registry.go index d9f53ee9..8283bf44 100644 --- a/docs/registry.go +++ b/docs/registry.go @@ -64,10 +64,11 @@ func (r *Registry) LookupRemoteImage(imgId, registry string, authConfig *auth.Au } req.SetBasicAuth(authConfig.Username, authConfig.Password) res, err := rt.RoundTrip(req) - if err == nil { - defer res.Body.Close() + if err != nil { + return false } - return err == nil && res.StatusCode == 307 + res.Body.Close() + return res.StatusCode == 307 } func (r *Registry) getImagesInRepository(repository string, authConfig *auth.AuthConfig) ([]map[string]string, error) { @@ -155,18 +156,19 @@ func (r *Registry) GetRemoteTags(registries []string, repository string, token [ } req.Header.Set("Authorization", "Token "+strings.Join(token, ", ")) res, err := r.client.Do(req) - if err == nil { - defer res.Body.Close() - } utils.Debugf("Got status code %d from %s", res.StatusCode, endpoint) - if err != nil || (res.StatusCode != 200 && res.StatusCode != 404) { + if err != nil { + return nil, err + } + defer res.Body.Close() + + if res.StatusCode != 200 && res.StatusCode != 404 { continue } else if res.StatusCode == 404 { return nil, fmt.Errorf("Repository not found") } result := make(map[string]string) - rawJson, err := ioutil.ReadAll(res.Body) if err != nil { return nil, err From b9e67a8884b1d03536e0a50373aba6340d8bd892 Mon Sep 17 00:00:00 2001 From: Sam Alba Date: Mon, 3 Jun 2013 14:42:21 -0700 Subject: [PATCH 3/3] Disabled HTTP keep-alive in the default HTTP client for Registry calls --- docs/registry.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/registry.go b/docs/registry.go index 8283bf44..aeae3fe4 100644 --- a/docs/registry.go +++ b/docs/registry.go @@ -477,9 +477,15 @@ func NewRegistry(root string) *Registry { // If the auth file does not exist, keep going authConfig, _ := auth.LoadConfig(root) + httpTransport := &http.Transport{ + DisableKeepAlives: true, + } + r := &Registry{ authConfig: authConfig, - client: &http.Client{}, + client: &http.Client{ + Transport: httpTransport, + }, } r.client.Jar = cookiejar.NewCookieJar() return r