oxyno-zeta / s3-proxy

S3 Reverse Proxy with GET, PUT and DELETE methods and authentication (OpenID Connect and Basic Auth)
https://oxyno-zeta.github.io/s3-proxy/
Apache License 2.0
297 stars 33 forks source link

Potential memory leak #423

Closed armin-malek closed 6 months ago

armin-malek commented 7 months ago

after startup, it slowly starts using more memory, in a few hours it reaches over 1GB because it works just fine with much less memory usage at startup, I think it's caused by a memory leak

To Reproduce here is the config file I'm using my provider is Idrive e2

# Log configuration
log:
  # Log level
  level: info
  # Log format
  format: text
  # Log file path
  # filePath:

#Server configurations
server:
  listenAddr: ""
  port: 8080

# Targets map
targets:
  first-bucket:
    ## Mount point
    mount:
      path:
        - /mybucket/
    # ## Actions
    actions:
      # Action for GET requests on target
      GET:
        # Will allow GET requests
        enabled: true
        # Configuration for GET requests
        config:
          # Redirect with trailing slash when a file isn't found
          redirectWithTrailingSlashForNotFoundFile: true
          # Index document to display if exists in folder
          indexDocument: index.html
          # Allow to add headers to streamed files (can be templated)
          streamedFileHeaders: {}
          # Redirect to a S3 signed URL
          redirectToSignedUrl: false
          # Signed URL expiration time
          signedUrlExpiration: 15m
          # Disable listing
          # Note: This will return an empty list or you should change the folder list template (in general or in this target)
          disableListing: true
          # Webhooks
          webhooks: []
      # Action for PUT requests on target
      PUT:
        # Will allow PUT requests
        enabled: false
        # Configuration for PUT requests
        config:
          # Metadata key/values that will be put on S3 objects.
          # Values can be templated. Empty values will be flushed.
          metadata:
            key: value
          # System Metadata cases.
          # Values can be templated. Empty values will be flushed.
          systemMetadata:
            # Cache-Control value (will be put as header after)
            cacheControl: ""
            # Content-Disposition value (will be put as header after)
            contentDisposition: ""
            # Content-Encoding value (will be put as header after)
            contentEncoding: ""
            # Content-Language value (will be put as header after)
            contentLanguage: ""
            # Expires value (will be put as header after)
            # Side note: This must have the RFC3339 date format at the end.
            expires: ""
          # Storage class that will be used for uploaded objects
          # See storage class here: https://docs.aws.amazon.com/AmazonS3/latest/dev/storage-class-intro.html
          # Values can be templated. Empty values will be flushed.
          storageClass: STANDARD # GLACIER, ...
          # Will allow override objects if enabled
          allowOverride: false
          # Canned ACL put on each file uploaded.
          # https://docs.aws.amazon.com/AmazonS3/latest/userguide/acl-overview.html#canned-acl
          # cannedACL: ""
          # Webhooks
          webhooks: []
      # Action for DELETE requests on target
      DELETE:
        # Will allow DELETE requests
        enabled: false
        # Configuration for DELETE requests
        config:
          # Webhooks
          webhooks: []

    ## Bucket configuration
    bucket:
      name: mybucket
      prefix:
      region: eu-west-1
      s3Endpoint: "idrive-e2.com"
      disableSSL: false
      credentials:
        accessKey:
          env: S3_ACCESS
        secretKey:
          env: S3_KEY

Expected behavior less and stable ram usage

Version and platform (please complete the following information):

oxyno-zeta commented 7 months ago

Hello @armin-malek ,

Thanks for your issue.

I never used this provider so I can't say if it is coming from this or not. But I have other ideas in mind. Can you answer those questions please ?:

Regards,

armin-malek commented 7 months ago

we have close to 8 million files in the bucket and we serve around 7 objects per second (in reality it's a burst of 30 to 40 objects every few seconds), the average object size is around 70KB

oxyno-zeta commented 7 months ago

I think I have an idea of why.

People requesting different files all the time ? Or are they the same for multiple minutes ?

armin-malek commented 7 months ago

it's like an image hosting platform so yeah it should be mostly random objects

oxyno-zeta commented 7 months ago

Ok so I think I know why. This must come from prometheus metrics which are saving metrics per "request path". This can be patched for sure.

armin-malek commented 7 months ago

Ok so I think I know why. This must come from prometheus metrics which are saving metrics per "request path". This can be patched for sure.

I'm not familiar with the code base but maybe an option to disable the metrics in the config file should do the trick for now, i'll keep restarting the container every once in a while :)

oxyno-zeta commented 7 months ago

I've just released a new version. The 4.13.0 release have a configuration dedicated for this.

Here is an example:

# Metrics configuration
metrics:
  # Disable router path save in HTTP metrics
  disableRouterPath: true

That should fix your problem.

PS: Out of this, do you use s3-proxy to make a tile map server ?

armin-malek commented 7 months ago

thanks, it has solved the problem!

PS: Out of this, do you use s3-proxy to make a tile map server ? no it is just serving images from a private bucket for a machine learning project

armin-malek commented 7 months ago

out of this too currently it's logging every request to stdout, is there way to disable that too? i couldn't find it in the docs if i'm not mistaken writing to stdout is not exactly cheap what other log levels we have in the config file?

oxyno-zeta commented 7 months ago

Cool to hear this ! That's great!

Yes that's a feature to log everything. You can change the log level to error if you want only errors. All log levels from uber/zap logger are supported.

github-actions[bot] commented 6 months ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 10 days