Skip to content

Commit 8561542

Browse files
committed
Reintroduce timeout and keepalive for watch requests to match client-go
This will send sends keep-alive probes to the server every 30 seconds. These features were present prior to the 1.0 refactor but were inadvertently removed.
1 parent 27ba0e1 commit 8561542

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/watch.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export class Watch {
4040
const controller = new AbortController();
4141
requestInit.signal = controller.signal as AbortSignal;
4242
requestInit.method = 'GET';
43+
requestInit.timeout = 30000;
4344

4445
let doneCalled: boolean = false;
4546
const doneCallOnce = (err: any) => {
@@ -53,6 +54,15 @@ export class Watch {
5354
try {
5455
const response = await fetch(watchURL, requestInit);
5556

57+
// Enable socket keep-alive to prevent connection stalls
58+
if (requestInit.agent && typeof requestInit.agent === 'object') {
59+
for (const socket of Object.values(requestInit.agent.sockets).flat()) {
60+
if (socket) {
61+
socket.setKeepAlive(true, 30000);
62+
}
63+
}
64+
}
65+
5666
if (response.status === 200) {
5767
response.body.on('error', doneCallOnce);
5868
response.body.on('close', () => doneCallOnce(null));

0 commit comments

Comments
 (0)