Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix(Runtime): Wait for container to start up (#7548)

Carlos Freunda0c79f73888b
diff --git a/openhands/runtime/impl/docker/docker_runtime.py b/openhands/runtime/impl/docker/docker_runtime.py
index fb32e19c3e..17c74f9ee1 100644
--- a/openhands/runtime/impl/docker/docker_runtime.py
+++ b/openhands/runtime/impl/docker/docker_runtime.py
@@ -37,6 +37,16 @@ APP_PORT_RANGE_1 = (50000, 54999)
APP_PORT_RANGE_2 = (55000, 59999)
+def _is_retryable_wait_until_alive_error(exception):
+ if isinstance(exception, tenacity.RetryError):
+ cause = exception.last_attempt.exception()
+ return _is_retryable_wait_until_alive_error(cause)
+
+ return isinstance(
+ exception, (ConnectionError, httpx.NetworkError, httpx.RemoteProtocolError)
+ )
+
+
class DockerRuntime(ActionExecutionClient):
"""This runtime will subscribe the event stream.
@@ -347,7 +357,7 @@ class DockerRuntime(ActionExecutionClient):
@tenacity.retry(
stop=tenacity.stop_after_delay(120) | stop_if_should_exit(),
- retry=tenacity.retry_if_exception_type((ConnectionError, httpx.NetworkError)),
+ retry=tenacity.retry_if_exception(_is_retryable_wait_until_alive_error),
reraise=True,
wait=tenacity.wait_fixed(2),
)