gomods / athens

A Go module datastore and proxy
https://docs.gomods.io
MIT License
4.41k stars 497 forks source link

Athens leaks etcd leases #1886

Closed uhthomas closed 11 months ago

uhthomas commented 12 months ago

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):

Additional context

santiagoPinzonD commented 11 months ago

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 commented 11 months ago

@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 commented 11 months ago

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 commented 11 months ago

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 commented 11 months ago

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 commented 11 months ago

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 commented 11 months ago

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.