mirror of
https://github.com/All-Hands-AI/OpenHands.git
synced 2026-01-09 23:08:04 -05:00
ALL-4636 Resolution for connection leaks (#12144)
Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
@@ -154,8 +154,10 @@ class SaasUserAuth(UserAuth):
|
|||||||
try:
|
try:
|
||||||
# TODO: I think we can do this in a single request if we refactor
|
# TODO: I think we can do this in a single request if we refactor
|
||||||
with session_maker() as session:
|
with session_maker() as session:
|
||||||
tokens = session.query(AuthTokens).where(
|
tokens = (
|
||||||
AuthTokens.keycloak_user_id == self.user_id
|
session.query(AuthTokens)
|
||||||
|
.where(AuthTokens.keycloak_user_id == self.user_id)
|
||||||
|
.all()
|
||||||
)
|
)
|
||||||
|
|
||||||
for token in tokens:
|
for token in tokens:
|
||||||
|
|||||||
@@ -510,6 +510,10 @@ async def delete_conversation(
|
|||||||
if v1_result is not None:
|
if v1_result is not None:
|
||||||
return v1_result
|
return v1_result
|
||||||
|
|
||||||
|
# Close connections
|
||||||
|
await db_session.close()
|
||||||
|
await httpx_client.aclose()
|
||||||
|
|
||||||
# V0 conversation logic
|
# V0 conversation logic
|
||||||
return await _delete_v0_conversation(conversation_id, user_id)
|
return await _delete_v0_conversation(conversation_id, user_id)
|
||||||
|
|
||||||
@@ -551,11 +555,8 @@ async def _try_delete_v1_conversation(
|
|||||||
httpx_client,
|
httpx_client,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
except (ValueError, TypeError):
|
|
||||||
# Not a valid UUID, continue with V0 logic
|
|
||||||
pass
|
|
||||||
except Exception:
|
except Exception:
|
||||||
# Some other error, continue with V0 logic
|
# Continue with V0 logic
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|||||||
@@ -946,6 +946,10 @@ async def test_delete_conversation():
|
|||||||
# Create a mock sandbox service
|
# Create a mock sandbox service
|
||||||
mock_sandbox_service = MagicMock()
|
mock_sandbox_service = MagicMock()
|
||||||
|
|
||||||
|
# Create mock db_session and httpx_client
|
||||||
|
mock_db_session = AsyncMock()
|
||||||
|
mock_httpx_client = AsyncMock()
|
||||||
|
|
||||||
# Mock the conversation manager
|
# Mock the conversation manager
|
||||||
with patch(
|
with patch(
|
||||||
'openhands.server.routes.manage_conversations.conversation_manager'
|
'openhands.server.routes.manage_conversations.conversation_manager'
|
||||||
@@ -969,6 +973,8 @@ async def test_delete_conversation():
|
|||||||
app_conversation_service=mock_app_conversation_service,
|
app_conversation_service=mock_app_conversation_service,
|
||||||
app_conversation_info_service=mock_app_conversation_info_service,
|
app_conversation_info_service=mock_app_conversation_info_service,
|
||||||
sandbox_service=mock_sandbox_service,
|
sandbox_service=mock_sandbox_service,
|
||||||
|
db_session=mock_db_session,
|
||||||
|
httpx_client=mock_httpx_client,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Verify the result
|
# Verify the result
|
||||||
@@ -1090,6 +1096,10 @@ async def test_delete_v1_conversation_not_found():
|
|||||||
)
|
)
|
||||||
mock_service.delete_app_conversation = AsyncMock(return_value=False)
|
mock_service.delete_app_conversation = AsyncMock(return_value=False)
|
||||||
|
|
||||||
|
# Create mock db_session and httpx_client
|
||||||
|
mock_db_session = AsyncMock()
|
||||||
|
mock_httpx_client = AsyncMock()
|
||||||
|
|
||||||
# Call delete_conversation with V1 conversation ID
|
# Call delete_conversation with V1 conversation ID
|
||||||
result = await delete_conversation(
|
result = await delete_conversation(
|
||||||
request=MagicMock(),
|
request=MagicMock(),
|
||||||
@@ -1098,6 +1108,8 @@ async def test_delete_v1_conversation_not_found():
|
|||||||
app_conversation_service=mock_service,
|
app_conversation_service=mock_service,
|
||||||
app_conversation_info_service=mock_info_service,
|
app_conversation_info_service=mock_info_service,
|
||||||
sandbox_service=mock_sandbox_service,
|
sandbox_service=mock_sandbox_service,
|
||||||
|
db_session=mock_db_session,
|
||||||
|
httpx_client=mock_httpx_client,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Verify the result
|
# Verify the result
|
||||||
@@ -1171,6 +1183,10 @@ async def test_delete_v1_conversation_invalid_uuid():
|
|||||||
mock_sandbox_service = MagicMock()
|
mock_sandbox_service = MagicMock()
|
||||||
mock_sandbox_service_dep.return_value = mock_sandbox_service
|
mock_sandbox_service_dep.return_value = mock_sandbox_service
|
||||||
|
|
||||||
|
# Create mock db_session and httpx_client
|
||||||
|
mock_db_session = AsyncMock()
|
||||||
|
mock_httpx_client = AsyncMock()
|
||||||
|
|
||||||
# Call delete_conversation
|
# Call delete_conversation
|
||||||
result = await delete_conversation(
|
result = await delete_conversation(
|
||||||
request=MagicMock(),
|
request=MagicMock(),
|
||||||
@@ -1179,6 +1195,8 @@ async def test_delete_v1_conversation_invalid_uuid():
|
|||||||
app_conversation_service=mock_service,
|
app_conversation_service=mock_service,
|
||||||
app_conversation_info_service=mock_info_service,
|
app_conversation_info_service=mock_info_service,
|
||||||
sandbox_service=mock_sandbox_service,
|
sandbox_service=mock_sandbox_service,
|
||||||
|
db_session=mock_db_session,
|
||||||
|
httpx_client=mock_httpx_client,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Verify the result
|
# Verify the result
|
||||||
@@ -1264,6 +1282,10 @@ async def test_delete_v1_conversation_service_error():
|
|||||||
mock_runtime_cls.delete = AsyncMock()
|
mock_runtime_cls.delete = AsyncMock()
|
||||||
mock_get_runtime_cls.return_value = mock_runtime_cls
|
mock_get_runtime_cls.return_value = mock_runtime_cls
|
||||||
|
|
||||||
|
# Create mock db_session and httpx_client
|
||||||
|
mock_db_session = AsyncMock()
|
||||||
|
mock_httpx_client = AsyncMock()
|
||||||
|
|
||||||
# Call delete_conversation
|
# Call delete_conversation
|
||||||
result = await delete_conversation(
|
result = await delete_conversation(
|
||||||
request=MagicMock(),
|
request=MagicMock(),
|
||||||
@@ -1272,6 +1294,8 @@ async def test_delete_v1_conversation_service_error():
|
|||||||
app_conversation_service=mock_service,
|
app_conversation_service=mock_service,
|
||||||
app_conversation_info_service=mock_info_service,
|
app_conversation_info_service=mock_info_service,
|
||||||
sandbox_service=mock_sandbox_service,
|
sandbox_service=mock_sandbox_service,
|
||||||
|
db_session=mock_db_session,
|
||||||
|
httpx_client=mock_httpx_client,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Verify the result (should fallback to V0)
|
# Verify the result (should fallback to V0)
|
||||||
|
|||||||
Reference in New Issue
Block a user