Skip to content

Fix CDP Mode memory leak #3686

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mkdocs_build/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

regex>=2024.11.6
pymdown-extensions>=10.14.3
pipdeptree>=2.26.0
pipdeptree>=2.26.1
python-dateutil>=2.8.2
Markdown==3.8
click==8.1.8
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pip>=25.0.1
packaging>=25.0
setuptools~=70.2;python_version<"3.10"
setuptools>=78.1.0;python_version>="3.10"
setuptools>=78.1.1;python_version>="3.10"
wheel>=0.45.1
attrs>=25.3.0
certifi>=2025.1.31
Expand Down
2 changes: 1 addition & 1 deletion seleniumbase/__version__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# seleniumbase package
__version__ = "4.37.3"
__version__ = "4.37.4"
6 changes: 6 additions & 0 deletions seleniumbase/plugins/sb_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1367,6 +1367,12 @@ def SB(
"%s%s%s%s%s"
% (c1, left_space, end_text, right_space, cr)
)
if hasattr(sb_config, "_cdp_aclose"):
import asyncio
with suppress(Exception):
loop = asyncio.get_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(sb_config._cdp_aclose())
gc.collect()
if test and test_name and not test_passed and raise_test_failure:
raise exception
Expand Down
3 changes: 3 additions & 0 deletions seleniumbase/undetected/cdp_driver/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
)
import websockets
from websockets.protocol import State
from seleniumbase import config as sb_config
from . import cdp_util as util
import mycdp as cdp
import mycdp.network
Expand Down Expand Up @@ -270,6 +271,7 @@ async def aopen(self, **kw):
max_size=MAX_SIZE,
)
self.listener = Listener(self)
sb_config._cdp_aclose = self.aclose
except (Exception,) as e:
logger.debug("Exception during opening of websocket: %s", e)
if self.listener:
Expand Down Expand Up @@ -415,6 +417,7 @@ async def send(
if not _is_update:
await self._register_handlers()
await self.websocket.send(tx.message)
sb_config._cdp_aclose = self.aclose
try:
return await tx
except ProtocolException as e:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
'pip>=25.0.1',
'packaging>=25.0',
'setuptools~=70.2;python_version<"3.10"', # Newer ones had issues
'setuptools>=78.1.0;python_version>="3.10"',
'setuptools>=78.1.1;python_version>="3.10"',
'wheel>=0.45.1',
'attrs>=25.3.0',
"certifi>=2025.1.31",
Expand Down