Skip to content
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

Reintroduce timeout and keep-alive for watch requests to match client-go #2131

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions src/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class Watch {
const controller = new AbortController();
requestInit.signal = controller.signal as AbortSignal;
requestInit.method = 'GET';
requestInit.timeout = 30000;

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

// Enable socket keep-alive to prevent connection stalls
if (requestInit.agent && typeof requestInit.agent === 'object') {
for (const socket of Object.values(requestInit.agent.sockets).flat()) {
if (socket) {
socket.setKeepAlive(true, 30000);
}
}
}

if (response.status === 200) {
response.body.on('error', doneCallOnce);
response.body.on('close', () => doneCallOnce(null));
Expand Down
Loading