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