From 30b505641c26a559a86f9feb405f5e4ad6f265ec Mon Sep 17 00:00:00 2001 From: openhands Date: Mon, 27 Jan 2025 22:25:12 +0000 Subject: [PATCH] Fix file descriptor leak in S3FileStore.read() --- openhands/storage/s3.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openhands/storage/s3.py b/openhands/storage/s3.py index 429e660011e4..cb723355155d 100644 --- a/openhands/storage/s3.py +++ b/openhands/storage/s3.py @@ -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':