Skip to content

Commit

Permalink
fix(pkg/stash): close etcd sessions
Browse files Browse the repository at this point in the history
Athens creates a new session for each 'Stash' request and then never closes it.
The sessions (etcd leases) are consequently held forever and eventually leads
to resource exhaustion on the etcd cluster.

This has been fixed by closing the acquired session at the end of the request.

Fixes: gomods#1886
  • Loading branch information
uhthomas committed Sep 11, 2023
1 parent e248d22 commit 4727240
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pkg/stash/with_etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,15 @@ 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)
}
defer sess.Close()

mv := config.FmtModVer(mod, ver)
mu := concurrency.NewMutex(sesh, mv)
mu := concurrency.NewMutex(sess, mv)
err = mu.Lock(ctx)
if err != nil {
return ver, errors.E(op, err)
Expand Down

0 comments on commit 4727240

Please sign in to comment.