From ff22cbc2d3a26ebc71c255039f394482a21149ed Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Wed, 18 Feb 2015 22:08:07 -0800 Subject: [PATCH] fix panic in token discovery Signed-off-by: Victor Vieux --- discovery/token/token.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/discovery/token/token.go b/discovery/token/token.go index 5274bb9700..3d552e452a 100644 --- a/discovery/token/token.go +++ b/discovery/token/token.go @@ -49,9 +49,7 @@ func (s *TokenDiscoveryService) Fetch() ([]*discovery.Entry, error) { return nil, err } - if resp.Body != nil { - defer resp.Body.Close() - } + defer resp.Body.Close() var addrs []string if resp.StatusCode == http.StatusOK { @@ -81,9 +79,12 @@ func (s *TokenDiscoveryService) Register(addr string) error { resp, err := http.Post(fmt.Sprintf("%s/%s/%s", s.url, "clusters", s.token), "application/json", buf) - // Force connection close + if err != nil { + return err + } + resp.Body.Close() - return err + return nil } // CreateCluster returns a unique cluster token