From a0c79f73888b60117db75ccec12d4fbdc2cf889e Mon Sep 17 00:00:00 2001 From: Carlos Freund Date: Thu, 27 Mar 2025 20:55:06 +0100 Subject: [PATCH] fix(Runtime): Wait for container to start up (#7548) Co-authored-by: openhands Co-authored-by: tofarr --- openhands/runtime/impl/docker/docker_runtime.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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), )