diff --git a/etcdserver/api/v2auth/auth_requests.go b/etcdserver/api/v2auth/auth_requests.go index 21369860c..d6574ecca 100644 --- a/etcdserver/api/v2auth/auth_requests.go +++ b/etcdserver/api/v2auth/auth_requests.go @@ -32,7 +32,6 @@ func (s *store) ensureAuthDirectories() error { } for _, res := range []string{StorePermsPrefix, StorePermsPrefix + "/users/", StorePermsPrefix + "/roles/"} { ctx, cancel := context.WithTimeout(context.Background(), s.timeout) - defer cancel() pe := false rr := etcdserverpb.Request{ Method: "PUT", @@ -41,6 +40,7 @@ func (s *store) ensureAuthDirectories() error { PrevExist: &pe, } _, err := s.server.Do(ctx, rr) + cancel() if err != nil { if e, ok := err.(*v2error.Error); ok { if e.ErrorCode == v2error.EcodeNodeExist {