Skip to content

Commit

Permalink
Fix file descriptor leak in S3FileStore.read()
Browse files Browse the repository at this point in the history
  • Loading branch information
openhands-agent committed Jan 27, 2025
1 parent 0ba96ce commit 30b5056
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion openhands/storage/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ def write(self, path: str, contents: str | bytes) -> None:
def read(self, path: str) -> str:
try:
response = self.client.get_object(Bucket=self.bucket, Key=path)
return response['Body'].read().decode('utf-8')
with response['Body'] as stream:
return stream.read().decode('utf-8')
except botocore.exceptions.ClientError as e:
# Catch all S3-related errors
if e.response['Error']['Code'] == 'NoSuchBucket':
Expand Down

0 comments on commit 30b5056

Please sign in to comment.