remove keepaliveDisabled from server.ts. rename keepaliveTimer.

This commit is contained in:
David Fiala 2024-05-29 15:09:55 -07:00
parent a77d94f7c6
commit c2da436a8e
2 changed files with 20 additions and 24 deletions

View File

@ -1384,8 +1384,7 @@ export class Server {
let connectionAgeTimer: NodeJS.Timeout | null = null;
let connectionAgeGraceTimer: NodeJS.Timeout | null = null;
let keepaliveTimeout: NodeJS.Timeout | null = null;
let keepaliveDisabled = false;
let keepaliveTimer: NodeJS.Timeout | null = null;
let sessionClosedByServer = false;
const idleTimeoutObj = this.enableIdleTimeout(session);
@ -1429,15 +1428,15 @@ export class Server {
}
const clearKeepaliveTimeout = () => {
if (keepaliveTimeout) {
clearTimeout(keepaliveTimeout);
keepaliveTimeout = null;
if (keepaliveTimer) {
clearTimeout(keepaliveTimer);
keepaliveTimer = null;
}
};
const canSendPing = () => {
return (
!keepaliveDisabled &&
!session.destroyed &&
this.keepaliveTimeMs < KEEPALIVE_MAX_TIME_MS &&
this.keepaliveTimeMs > 0
);
@ -1453,11 +1452,11 @@ export class Server {
this.keepaliveTrace(
'Starting keepalive timer for ' + this.keepaliveTimeMs + 'ms'
);
keepaliveTimeout = setTimeout(() => {
keepaliveTimer = setTimeout(() => {
clearKeepaliveTimeout();
sendPing();
}, this.keepaliveTimeMs);
keepaliveTimeout.unref?.();
keepaliveTimer.unref?.();
};
sendPing = () => {
@ -1501,14 +1500,14 @@ export class Server {
return;
}
keepaliveTimeout = setTimeout(() => {
keepaliveTimer = setTimeout(() => {
clearKeepaliveTimeout();
this.keepaliveTrace('Ping timeout passed without response');
this.trace('Connection dropped by keepalive timeout');
sessionClosedByServer = true;
session.close();
}, this.keepaliveTimeoutMs);
keepaliveTimeout.unref?.();
keepaliveTimer.unref?.();
};
maybeStartKeepalivePingTimer();
@ -1528,7 +1527,6 @@ export class Server {
clearTimeout(connectionAgeGraceTimer);
}
keepaliveDisabled = true;
clearKeepaliveTimeout();
if (idleTimeoutObj !== null) {
@ -1575,7 +1573,6 @@ export class Server {
let connectionAgeTimer: NodeJS.Timeout | null = null;
let connectionAgeGraceTimer: NodeJS.Timeout | null = null;
let keepaliveTimeout: NodeJS.Timeout | null = null;
let keepaliveDisabled = false;
let sessionClosedByServer = false;
const idleTimeoutObj = this.enableIdleTimeout(session);
@ -1626,7 +1623,7 @@ export class Server {
const canSendPing = () => {
return (
!keepaliveDisabled &&
!session.destroyed &&
this.keepaliveTimeMs < KEEPALIVE_MAX_TIME_MS &&
this.keepaliveTimeMs > 0
);
@ -1734,7 +1731,6 @@ export class Server {
clearTimeout(connectionAgeGraceTimer);
}
keepaliveDisabled = true;
clearKeepaliveTimeout();
if (idleTimeoutObj !== null) {

View File

@ -113,7 +113,7 @@ class Http2Transport implements Transport {
/**
* Timer reference indicating when to send the next ping or when the most recent ping will be considered lost.
*/
private keepaliveTimeout: NodeJS.Timeout | null = null;
private keepaliveTimer: NodeJS.Timeout | null = null;
/**
* Indicates that the keepalive timer ran out while there were no active
* calls, and a ping should be sent the next time a call starts.
@ -416,7 +416,7 @@ class Http2Transport implements Transport {
this.pendingSendKeepalivePing = true;
return;
}
if (this.keepaliveTimeout) {
if (this.keepaliveTimer) {
console.error('keepaliveTimeout is not null');
return;
}
@ -426,11 +426,11 @@ class Http2Transport implements Transport {
this.keepaliveTrace(
'Sending ping with timeout ' + this.keepaliveTimeoutMs + 'ms'
);
this.keepaliveTimeout = setTimeout(() => {
this.keepaliveTimer = setTimeout(() => {
this.keepaliveTrace('Ping timeout passed without response');
this.handleDisconnect();
}, this.keepaliveTimeoutMs);
this.keepaliveTimeout.unref?.();
this.keepaliveTimer.unref?.();
let pingSendError = '';
try {
const pingSentSuccessfully = this.session.ping(
@ -471,14 +471,14 @@ class Http2Transport implements Transport {
if (this.pendingSendKeepalivePing) {
this.pendingSendKeepalivePing = false;
this.maybeSendPing();
} else if (!this.keepaliveTimeout) {
} else if (!this.keepaliveTimer) {
this.keepaliveTrace(
'Starting keepalive timer for ' + this.keepaliveTimeMs + 'ms'
);
this.keepaliveTimeout = setTimeout(() => {
this.keepaliveTimer = setTimeout(() => {
this.maybeSendPing();
}, this.keepaliveTimeMs);
this.keepaliveTimeout.unref?.();
this.keepaliveTimer.unref?.();
}
/* Otherwise, there is already either a keepalive timer or a ping pending,
* wait for those to resolve. */
@ -488,9 +488,9 @@ class Http2Transport implements Transport {
* Clears whichever keepalive timeout is currently active, if any.
*/
private clearKeepaliveTimeout() {
if (this.keepaliveTimeout) {
clearTimeout(this.keepaliveTimeout);
this.keepaliveTimeout = null;
if (this.keepaliveTimer) {
clearTimeout(this.keepaliveTimer);
this.keepaliveTimer = null;
}
}