Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Athens leaks etcd leases #1886

Closed
uhthomas opened this issue Sep 11, 2023 · 7 comments · Fixed by #1887
Closed

Athens leaks etcd leases #1886

uhthomas opened this issue Sep 11, 2023 · 7 comments · Fixed by #1887

Comments

@uhthomas
Copy link
Contributor

Describe the bug

Athens creates a new session (lease) for each stash request, and then never closes the session. The leases are then held indefinitely, or until the process is restarted, which causes excessive load on the etcd cluster and eventually overloads it.

Screenshot 2023-09-11 at 22 31 10 Screenshot 2023-09-11 at 22 32 27

The spikes are from restarting Athens.

Error Message

N/A

To Reproduce
Steps to reproduce the behavior:

  1. Run Athens with etcd configured for singleflight.
  2. Make a few thousands requests for modules which aren't already cached.
  3. Observe the number of leases increases indefinitely.

Expected behavior

Athens should either create a single session for all locks, or close the session. I am not sure which is correct as I could not find great documentation on what is recommended by the etcd authors. I imagine it's probably best just to make sure the session is closed.

Environment (please complete the following information):

  • OS: Linux
  • Go version: N/A
  • Proxy version: e248d22
  • Storage (fs/mongodb/s3 etc.): etcd and s3

Additional context

uhthomas added a commit to uhthomas/athens that referenced this issue Sep 11, 2023
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.

Fixes: gomods#1886
uhthomas added a commit to uhthomas/athens that referenced this issue Sep 11, 2023
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
uhthomas added a commit to uhthomas/athens that referenced this issue Sep 11, 2023
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
uhthomas added a commit to uhthomas/athens that referenced this issue Sep 11, 2023
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
uhthomas added a commit to uhthomas/athens that referenced this issue Sep 11, 2023
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
uhthomas added a commit to uhthomas/athens that referenced this issue Sep 11, 2023
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
uhthomas added a commit to uhthomas/athens that referenced this issue Sep 11, 2023
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
uhthomas added a commit to uhthomas/athens that referenced this issue Sep 11, 2023
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
uhthomas added a commit to uhthomas/athens that referenced this issue Sep 13, 2023
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
uhthomas added a commit to uhthomas/athens that referenced this issue Sep 14, 2023
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
uhthomas added a commit to uhthomas/athens that referenced this issue Sep 18, 2023
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
@santiagoPinzonD
Copy link

Hello, @uhthomas wanted to know how did you solve this problem ?
I know that the fix is already in the code but not yet released.
this is my singleflight config, I have a lot of traffic and I have to restart constantly because it consumes the machine's memory.
image

@uhthomas
Copy link
Contributor Author

@santiagoPinzonD You will have to build Athens from source.

FROM golang:1.21.3-alpine AS build

RUN apk update && apk add git

RUN go install github.com/gomods/athens/cmd/proxy@main

FROM gomods/athens:v0.12.1

COPY --from=build /go/bin/proxy /bin/athens-proxy

@manugupt1
Copy link
Member

manugupt1 commented Oct 11, 2023

Please use canary tag which has more fixes and built from master's latest. I will see if I can do a release in coming weeks

@uhthomas
Copy link
Contributor Author

Thanks @manugupt1, wasn't aware of this image - though it is a shame that there aren't tags for each commit.

Current latest digest for canary: gomods/athens:canary@sha256:372c9cb22c767f86e8c15a4534b3dcdc837f6bc7a667647a0458814cc0cdc59e

@r-ashish
Copy link
Member

We do have tags for every commit but under a separate registry: https://hub.docker.com/r/gomods/athens-dev/tags. Feel free to use it if you wanna pin to a specific commit until the next stable version is released.

@santiagoPinzonD
Copy link

Done, thanks guys
yesterday I put in production the canary, let's see if it manages to solve the memory problem, I take this opportunity to ask you, we currently have two organizations in github, so we are running two athens container on the same server, this apparently has not been a problem, until we doubled the traffic an average of 20 million request, I opened another issue regarding this issue and commented that you can outsource the database.
is there any guide about this? and how can I improve the performance?

@uhthomas
Copy link
Contributor Author

What specifically are you asking, sorry? There is no database required for Athens. Just use an S3-compatible storage system and the existing etcd cluster. You shouldn't need a separate instance of Athens per GitHub organisation either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants