Closed mcrute closed 3 months ago
The recent changes to the S3Proxy
class in s3proxy.go
focus on enhancing resource management by implementing defer
statements to ensure that the bodies of S3 object responses are properly closed after use. This aims to prevent resource leaks and improve the application’s stability and performance, particularly in long-running processes.
Files | Change Summary |
---|---|
s3proxy.go |
Added defer obj.Body.Close() in the serveErrorPage method and multiple instances in the GetHandler method to ensure proper closure of S3 object bodies. |
Objective | Addressed | Explanation |
---|---|---|
High CPU usage after 32 days with caddy-s3-proxy (#64) | ✅ |
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
Eh... this change didn't really fix the issue. Although it also didn't make it worse so it might be worth merging. That being said I've migrated to caddy-fs-s3 instead so I'm going to withdraw this PR.
Calls to the
GetObject
method of the S3 client require that theBody
be closed to avoid leaking memory. The returned struct is anhttp.Response
returned by anhttp.Client
(verified by digging into the AWS SDK dependency chain) and is guaranteed to always have a non-nilBody
.The only way I've been able to spot this issue is in prod after a few days of load. I'm testing this patch now and it already appears to be holding Caddy memory usage much more steady.
Related to and should fix #64.
Summary by CodeRabbit