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

Fix file descriptor leak in S3FileStore #6486

Merged
merged 1 commit into from
Jan 28, 2025
Merged

Conversation

rbren
Copy link
Collaborator

@rbren rbren commented Jan 27, 2025

This PR fixes a potential file descriptor leak in the S3FileStore implementation. The issue was in the read() method where the StreamingBody object from boto3 was not being properly closed after use.

Changes

  • Modified read() method to use a context manager (with statement) to ensure proper cleanup of the StreamingBody object

Why

  • The StreamingBody object from boto3 maintains an open HTTP connection to S3
  • Without proper closing, these connections can accumulate over time
  • This can lead to resource exhaustion, particularly in long-running applications or those that read many files

The fix ensures that the stream is properly closed even if an error occurs during reading, preventing file descriptor leaks.


To run this PR locally, use the following command:

docker run -it --rm   -p 3000:3000   -v /var/run/docker.sock:/var/run/docker.sock   --add-host host.docker.internal:host-gateway   -e SANDBOX_RUNTIME_CONTAINER_IMAGE=docker.all-hands.dev/all-hands-ai/runtime:30b5056-nikolaik   --name openhands-app-30b5056   docker.all-hands.dev/all-hands-ai/openhands:30b5056

@rbren rbren marked this pull request as ready for review January 27, 2025 22:26
@rbren rbren merged commit f3b8bad into main Jan 28, 2025
14 checks passed
@rbren rbren deleted the fix-s3-file-descriptor-leak branch January 28, 2025 16:47
zchn pushed a commit to zchn/OpenHands that referenced this pull request Feb 4, 2025
idagelic pushed a commit to idagelic/OpenHands that referenced this pull request Feb 12, 2025
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 this pull request may close these issues.

3 participants