From ee701eacc2a74de9be0a6aff4f5aeb40f8dfc2b4 Mon Sep 17 00:00:00 2001 From: Robert Brennan Date: Thu, 9 Jan 2025 19:26:53 -0500 Subject: [PATCH] fix: prevent race condition in session manager during disconnect (#6053) Co-authored-by: openhands --- openhands/server/session/manager.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/openhands/server/session/manager.py b/openhands/server/session/manager.py index c7577cc1b558..9e7f7d8b8d7f 100644 --- a/openhands/server/session/manager.py +++ b/openhands/server/session/manager.py @@ -165,10 +165,9 @@ async def _process_message(self, message: dict): # which can't be guaranteed - nodes can simply vanish unexpectedly! sid = data['sid'] logger.debug(f'session_closing:{sid}') - for ( - connection_id, - local_sid, - ) in self.local_connection_id_to_session_id.items(): + # Create a list of items to process to avoid modifying dict during iteration + items = list(self.local_connection_id_to_session_id.items()) + for connection_id, local_sid in items: if sid == local_sid: logger.warning( 'local_connection_to_closing_session:{connection_id}:{sid}'