Enable TCP Keep-Alive on WebSockets
This commit is contained in:
parent
7a512dfbed
commit
47c0cc053a
1 changed files with 3 additions and 0 deletions
|
@ -17,6 +17,7 @@ import { ConnectTimeoutError, HTTPError } from './Errors';
|
||||||
import { handleStatusCode, translateError } from './Utils';
|
import { handleStatusCode, translateError } from './Utils';
|
||||||
|
|
||||||
const TEN_SECONDS = 10 * durations.SECOND;
|
const TEN_SECONDS = 10 * durations.SECOND;
|
||||||
|
const KEEPALIVE_INTERVAL_MS = TEN_SECONDS;
|
||||||
|
|
||||||
export type IResource = {
|
export type IResource = {
|
||||||
close(code: number, reason: string): void;
|
close(code: number, reason: string): void;
|
||||||
|
@ -76,6 +77,8 @@ export function connect<Resource extends IResource>({
|
||||||
client.on('connect', socket => {
|
client.on('connect', socket => {
|
||||||
Timers.clearTimeout(timer);
|
Timers.clearTimeout(timer);
|
||||||
|
|
||||||
|
socket.socket.setKeepAlive(true, KEEPALIVE_INTERVAL_MS);
|
||||||
|
|
||||||
resource = createResource(socket);
|
resource = createResource(socket);
|
||||||
resolve(resource);
|
resolve(resource);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue