diff --git a/.golangci.yml b/.golangci.yml index d757d9dba..3111c62b3 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -6,6 +6,10 @@ linters-settings: cyclop: max-complexity: 12 skip-tests: true + errcheck: + exclude-functions: + - (*go.etcd.io/etcd/client/v3/concurrency.Mutex).Unlock + - (*go.etcd.io/etcd/client/v3/concurrency.Session).Close gofumpt: extra-rules: true @@ -50,15 +54,15 @@ linters: issues: exclude-use-default: false exclude: - - 'package-comments: should have a package comment' - - 'ST1000: at least one file in a package should have a package comment' - - 'G204: Subprocess launched with a potential tainted input or cmd arguments' - - 'G204: Subprocess launched with variable' - - 'G402: TLS MinVersion too low.' - - 'const `op` is unused' + - "package-comments: should have a package comment" + - "ST1000: at least one file in a package should have a package comment" + - "G204: Subprocess launched with a potential tainted input or cmd arguments" + - "G204: Subprocess launched with variable" + - "G402: TLS MinVersion too low." + - "const `op` is unused" exclude-rules: - path: cmd/proxy/main.go - text: 'G108: Profiling endpoint is automatically exposed on /debug/pprof' + text: "G108: Profiling endpoint is automatically exposed on /debug/pprof" - path: pkg/stash/stasher.go linters: - contextcheck diff --git a/pkg/stash/with_etcd.go b/pkg/stash/with_etcd.go index 1cd8d2f97..9faccbb91 100644 --- a/pkg/stash/with_etcd.go +++ b/pkg/stash/with_etcd.go @@ -56,30 +56,28 @@ func (s *etcd) Stash(ctx context.Context, mod, ver string) (newVer string, err e const op errors.Op = "etcd.Stash" ctx, span := observ.StartSpan(ctx, op.String()) defer span.End() - sesh, err := concurrency.NewSession(s.client) + + sess, err := concurrency.NewSession(s.client) if err != nil { return ver, errors.E(op, err) } - mv := config.FmtModVer(mod, ver) - mu := concurrency.NewMutex(sesh, mv) - err = mu.Lock(ctx) - if err != nil { + defer sess.Close() + + m := concurrency.NewMutex(sess, config.FmtModVer(mod, ver)) + if err := m.Lock(ctx); err != nil { return ver, errors.E(op, err) } - defer func() { - const op errors.Op = "etcd.Unlock" - lockErr := mu.Unlock(ctx) - if err == nil && lockErr != nil { - err = errors.E(op, lockErr) - } - }() + defer m.Unlock(ctx) + ok, err := s.checker.Exists(ctx, mod, ver) if err != nil { return ver, errors.E(op, err) } + if ok { return ver, nil } + newVer, err = s.stasher.Stash(ctx, mod, ver) if err != nil { return ver, errors.E(op, err)