fix: properly clean up sessions when Docker containers are destroyed

- close_session() now calls on_session_end() to remove the session from
  sessions dict and routes, preventing zombie entries that persist after
  the container is gone
- _remove_container() now closes the active session before removing the
  app from apps_by_slug/apps, so session cleanup can still reference the
  app during teardown
- Updated and added tests to verify session tracking cleanup
This commit is contained in:
GitHub Copilot
2026-02-06 17:27:49 +00:00
parent 8513283eae
commit b87a698438
4 changed files with 43 additions and 11 deletions
+5 -1
View File
@@ -137,17 +137,21 @@ class TestSessionManager:
@pytest.mark.asyncio
async def test_close_session(self, mock_poller, mock_path, sample_apps):
"""Test closing a specific session."""
"""Test closing a specific session removes it from tracking."""
manager = SessionManager(mock_poller, mock_path, sample_apps)
mock_session = MagicMock()
mock_session.close = AsyncMock()
session_id = SessionID("test-session")
route_key = RouteKey("test-route")
manager.sessions[session_id] = mock_session
manager.routes[route_key] = session_id
await manager.close_session(session_id)
mock_session.close.assert_called_once()
assert session_id not in manager.sessions
assert route_key not in manager.routes
@pytest.mark.asyncio
async def test_close_session_nonexistent(self, mock_poller, mock_path, sample_apps):