Skip to content

πŸ™Œ OpenHands: AI-Driven Development

Fixes for minor cases where FDs were not closed (#6228)

tofarrb9884f7609fa
diff --git a/openhands/runtime/builder/remote.py b/openhands/runtime/builder/remote.py
index 2e2c67c5a8..eb35e13b5c 100644
--- a/openhands/runtime/builder/remote.py
+++ b/openhands/runtime/builder/remote.py
@@ -18,10 +18,12 @@ from openhands.utils.shutdown_listener import (
class RemoteRuntimeBuilder(RuntimeBuilder):
"""This class interacts with the remote Runtime API for building and managing container images."""
- def __init__(self, api_url: str, api_key: str):
+ def __init__(
+ self, api_url: str, api_key: str, session: requests.Session | None = None
+ ):
self.api_url = api_url
self.api_key = api_key
- self.session = requests.Session()
+ self.session = session or requests.Session()
self.session.headers.update({'X-API-Key': self.api_key})
def build(
diff --git a/openhands/runtime/impl/remote/remote_runtime.py b/openhands/runtime/impl/remote/remote_runtime.py
index ebc1a86b38..bb5135dff5 100644
--- a/openhands/runtime/impl/remote/remote_runtime.py
+++ b/openhands/runtime/impl/remote/remote_runtime.py
@@ -66,7 +66,9 @@ class RemoteRuntime(ActionExecutionClient):
)
self.runtime_builder = RemoteRuntimeBuilder(
- self.config.sandbox.remote_runtime_api_url, self.config.sandbox.api_key
+ self.config.sandbox.remote_runtime_api_url,
+ self.config.sandbox.api_key,
+ self.session,
)
self.runtime_id: str | None = None
self.runtime_url: str | None = None
diff --git a/openhands/runtime/utils/request.py b/openhands/runtime/utils/request.py
index 2a0e17aa0f..e05a083e7b 100644
--- a/openhands/runtime/utils/request.py
+++ b/openhands/runtime/utils/request.py
@@ -48,6 +48,8 @@ def send_request(
_json = response.json()
except (requests.exceptions.JSONDecodeError, json.decoder.JSONDecodeError):
_json = None
+ finally:
+ response.close()
raise RequestHTTPError(
e,
response=e.response,