Skip to content

πŸ™Œ OpenHands: AI-Driven Development

Fix: Agent gets stuck in closing and server won't die (#5675)

tofarr5498ca1f8bb7
diff --git a/openhands/server/session/agent_session.py b/openhands/server/session/agent_session.py
index d405ed7ab4..17bd3c6d1c 100644
--- a/openhands/server/session/agent_session.py
+++ b/openhands/server/session/agent_session.py
@@ -15,6 +15,7 @@ from openhands.runtime.base import Runtime, RuntimeUnavailableError
from openhands.security import SecurityAnalyzer, options
from openhands.storage.files import FileStore
from openhands.utils.async_utils import call_async_from_sync
+from openhands.utils.shutdown_listener import should_continue
WAIT_TIME_BEFORE_CLOSE = 300
WAIT_TIME_BEFORE_CLOSE_INTERVAL = 5
@@ -152,7 +153,7 @@ class AgentSession:
async def _close(self):
seconds_waited = 0
- while self._initializing:
+ while self._initializing and should_continue():
logger.debug(
f'Waiting for initialization to finish before closing session {self.sid}'
)