Add optional websocket keepalive pings for idle Exec sessions#2878
Add optional websocket keepalive pings for idle Exec sessions#2878Copilot wants to merge 5 commits into
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Copilot The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
mstruebing
left a comment
There was a problem hiding this comment.
/lgtm
Will leave it in this state for now. to give others the chance to look at it.
|
|
||
| const timer = setInterval(() => { | ||
| if (conn.readyState === WebSocket.OPEN) { | ||
| socket.ping!(); |
There was a problem hiding this comment.
Please add handling for the pong message.
|
@copilot mostly looks good, please add handling for the pong message. |
|
New changes are detected. LGTM label has been removed. |
|
cjihrig
left a comment
There was a problem hiding this comment.
Two minor, optional nits, but LGTM.
| return true; | ||
| }); | ||
| const pingIntervalMs = options?.pingIntervalMs; | ||
| if (pingIntervalMs !== undefined && Number.isInteger(pingIntervalMs) && pingIntervalMs > 0) { |
There was a problem hiding this comment.
Will this silently ignore invalid pingIntervalMs values? If so, maybe it should throw instead.
| const onPong = () => { | ||
| awaitingPong = false; | ||
| }; | ||
| const clearKeepAlive = () => { | ||
| clearInterval(timer); | ||
| socket.removeListener?.('pong', onPong); | ||
| }; | ||
| socket.on?.('pong', onPong); | ||
| socket.on?.('close', clearKeepAlive); | ||
| socket.on?.('error', clearKeepAlive); |
There was a problem hiding this comment.
Maybe this block should be conditional based on whether socket.on is a function or not.
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: cjihrig, Copilot The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Exec websocket sessions can be dropped around the 5-minute mark in some proxy/network paths when no traffic is sent. This change adds an opt-in keepalive mechanism for
Execwithout changing default behavior.API: opt-in exec keepalive
ExecOptionswithpingIntervalMs?: number.Exec.exec(...)with an optional trailingoptionsparameter.Behavior: ping/pong-aware websocket keepalive
pingIntervalMsis a positive integer,Execsends websocket ping frames while the socket is open.ping().Lifecycle: cleanup on termination
closeanderrorto avoid orphaned intervals.Coverage: focused unit test
exec_testcase validating that pings are emitted when configured, pong handling enables subsequent pings, and pings stop after close.