-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
Describe the bug
I notice that when reading (or writing) objects out of an S3 bucket using the aws-sdk-s3 (1.176.0) gem, a TCP connection is left in the CLOSE_WAIT state. This only goes away when the process running the Ruby program that initiated the connection dies.
This isn't really an issue locally, but in the production server which is a multi-process web-server (Passenger+Nginx), it appears these persistent connections slowly consume system resources to the point of complete exhaustion. I'm genuinely curious if this decision to leave these connections in CLOSE_WAIT was intentional and just a really poor fit for our production environment, or if it was done by mistake. Regardless, it seems at the very least imprudent to keep these connections in CLOSE_WAIT for the lifecycle of the initiating process.
I noticed this after enabling active-storage for our application, and it would slowly consume all RAM until the application crashes. Passenger is unable to re-use these web processes due to them having a TCP socket in CLOSE_WAIT, so it keeps spawning more until all system resources are maxed out.
Ruby version: 3.3.6
Regression Issue
- Select this option if this issue appears to be a regression.
Expected Behavior
I would not expect any evidence of a TCP connection to the S3 service once transmission is completed.
Current Behavior
After reading from an S3 bucket, a TCP socket is left in CLOSE_WAIT state.
Reproduction Steps
- Run
lsof -i -P | grep CLOSE_WAIT
and notice there are no TCP connections to an AWS resource in CLOSE_WAIT. - Read from an S3 bucket in a Ruby console
- Run
lsof -i -P | grep CLOSE_WAIT
and notice a TCP socket for AWS in CLOSE_WAIT. - Terminate the Ruby console
- Run
lsof -i -P | grep CLOSE_WAIT
and notice this CLOSE_WAIT socket goes away.
Possible Solution
Close the TCP socket upon completion of transmission.
Additional Information/Context
No response
Gem name ('aws-sdk', 'aws-sdk-resources' or service gems like 'aws-sdk-s3') and its version
aws-sdk-s3 (1.176.0)
Environment details (Version of Ruby, OS environment)
Ruby 3.3.6, macOS 14.6.1