Skip to content
Open
Changes from 1 commit
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
18 changes: 18 additions & 0 deletions cdp_use/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,26 @@ def __init__(
url: str,
additional_headers: Optional[Dict[str, str]] = None,
max_ws_frame_size: int = 100 * 1024 * 1024, # Default 100MB
ping_interval: Optional[float] = None,
ping_timeout: Optional[float] = None,
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
):
# `ping_interval`/`ping_timeout` default to None (disabled), not the
# `websockets` library's own defaults (20s/20s). CDP is a request/
# response protocol over this same socket, so its own traffic is
# already sufficient liveness detection; the library's independent
# keepalive ping can time out under real load (a browser busy
# servicing a heavy command, or added latency on a cloud/remote
# session) well before the connection has actually died, closing it
# with code 1011 and surfacing as an unexplained mid-session drop
# (e.g. #4688). This file's own PING/PONG logging above already
# tracks exactly that timeout window, which is a sign the failure
# mode has been hit before. Pass explicit values to restore the
# library defaults if you want transport-level liveness checks.
self.url = url
self.additional_headers = additional_headers
self.max_ws_frame_size = max_ws_frame_size
self.ping_interval = ping_interval
self.ping_timeout = ping_timeout
self.ws: Optional[websockets.ClientConnection] = None
self.msg_id: int = 0
self.pending_requests: Dict[int, asyncio.Future] = {}
Expand Down Expand Up @@ -271,6 +287,8 @@ async def start(self):
)
connect_kwargs = {
"max_size": self.max_ws_frame_size,
"ping_interval": self.ping_interval,

@cubic-dev-ai cubic-dev-ai Bot Aug 20, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: With keepalive pings disabled by default (ping_interval=None), a connection that dies silently—network partition or drop with no TCP FIN/RST—is no longer detected. Both await self.ws.recv() in _handle_messages and await future in send_raw block indefinitely, so CDP commands hang forever instead of failing fast as they did when a missed pong closed the socket after ~20s. The comment's claim that CDP's own traffic is 'sufficient liveness detection' only holds while traffic is flowing; during idle moments a dead connection is indistinguishable from a live one. Consider keeping detection available (e.g., a conservative non-None default such as a long ping_interval, or an application-level request timeout) rather than removing it entirely, and document that None means commands can hang when the socket dies without an RST.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At cdp_use/client.py, line 290:

<comment>With keepalive pings disabled by default (ping_interval=None), a connection that dies silently—network partition or drop with no TCP FIN/RST—is no longer detected. Both `await self.ws.recv()` in `_handle_messages` and `await future` in `send_raw` block indefinitely, so CDP commands hang forever instead of failing fast as they did when a missed pong closed the socket after ~20s. The comment's claim that CDP's own traffic is 'sufficient liveness detection' only holds while traffic is flowing; during idle moments a dead connection is indistinguishable from a live one. Consider keeping detection available (e.g., a conservative non-None default such as a long ping_interval, or an application-level request timeout) rather than removing it entirely, and document that None means commands can hang when the socket dies without an RST.</comment>

<file context>
@@ -271,6 +287,8 @@ async def start(self):
         )
         connect_kwargs = {
             "max_size": self.max_ws_frame_size,
+            "ping_interval": self.ping_interval,
+            "ping_timeout": self.ping_timeout,
         }
</file context>
Fix with cubic

"ping_timeout": self.ping_timeout,
}
if self.additional_headers:
connect_kwargs["additional_headers"] = self.additional_headers
Expand Down