Skip to content

Commit

Permalink
Fixes for minor cases where FDs were not closed (#6228)
Browse files Browse the repository at this point in the history
  • Loading branch information
tofarr authored Jan 13, 2025
1 parent 99eda0e commit b9884f7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
6 changes: 4 additions & 2 deletions openhands/runtime/builder/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
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(
Expand Down
4 changes: 3 additions & 1 deletion openhands/runtime/impl/remote/remote_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ def __init__(
)

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
Expand Down
2 changes: 2 additions & 0 deletions openhands/runtime/utils/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit b9884f7

Please sign in to comment.