-
Notifications
You must be signed in to change notification settings - Fork 37
Make websocket ping_interval/ping_timeout configurable (default off) to avoid false 1011 disconnects #25
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
base: main
Are you sure you want to change the base?
Make websocket ping_interval/ping_timeout configurable (default off) to avoid false 1011 disconnects #25
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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, | ||
| ): | ||
| # `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] = {} | ||
|
|
@@ -271,6 +287,8 @@ async def start(self): | |
| ) | ||
| connect_kwargs = { | ||
| "max_size": self.max_ws_frame_size, | ||
| "ping_interval": self.ping_interval, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Prompt for AI agents |
||
| "ping_timeout": self.ping_timeout, | ||
| } | ||
| if self.additional_headers: | ||
| connect_kwargs["additional_headers"] = self.additional_headers | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.