Enable TCP Keep-Alive on WebSockets

This commit is contained in:
Fedor Indutny
2023-06-21 21:05:44 +02:00
committed by GitHub
parent 7a512dfbed
commit 47c0cc053a

View File

@@ -17,6 +17,7 @@ import { ConnectTimeoutError, HTTPError } from './Errors';
import { handleStatusCode, translateError } from './Utils';
const TEN_SECONDS = 10 * durations.SECOND;
const KEEPALIVE_INTERVAL_MS = TEN_SECONDS;
export type IResource = {
close(code: number, reason: string): void;
@@ -76,6 +77,8 @@ export function connect<Resource extends IResource>({
client.on('connect', socket => {
Timers.clearTimeout(timer);
socket.socket.setKeepAlive(true, KEEPALIVE_INTERVAL_MS);
resource = createResource(socket);
resolve(resource);
});