Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
fix: close CloudBrowserClient httpx pool on session stop to prevent memory leak
LarsenCundric5e644981e82c
diff --git a/browser_use/browser/cloud/cloud.py b/browser_use/browser/cloud/cloud.pyindex 78f4eccf4..757b64dd4 100644--- a/browser_use/browser/cloud/cloud.py+++ b/browser_use/browser/cloud/cloud.py@@ -192,7 +192,10 @@ class CloudBrowserClient:raise CloudBrowserError(f'Unexpected error stopping cloud browser: {e}')async def close(self):- """Close the HTTP client and cleanup any active sessions."""+ """Close the HTTP client and cleanup any active sessions.++ Safe to call multiple times — subsequent calls are no-ops.+ """# Try to stop current session if activeif self.current_session_id:try:@@ -200,4 +203,5 @@ class CloudBrowserClient:except Exception as e:logger.debug(f'Failed to stop cloud browser session during cleanup: {e}')- await self.client.aclose()+ if not self.client.is_closed:+ await self.client.aclose()diff --git a/browser_use/browser/session.py b/browser_use/browser/session.pyindex 9a5bdd42f..c2e799da6 100644--- a/browser_use/browser/session.py+++ b/browser_use/browser/session.py@@ -1217,6 +1217,12 @@ class BrowserSession(BaseModel):self.logger.info(f'🌤️ Cloud browser session cleaned up: {cloud_session_id}')except Exception as e:self.logger.debug(f'Failed to cleanup cloud browser session {cloud_session_id}: {e}')+ finally:+ # Always close the httpx client to free connection pool memory+ try:+ await self._cloud_browser_client.close()+ except Exception:+ pass# Clear CDP session cache before stoppingself.logger.info(