Skip to content

Commit c2da436

Browse files
committed
remove keepaliveDisabled from server.ts. rename keepaliveTimer.
1 parent a77d94f commit c2da436

File tree

2 files changed

+20
-24
lines changed

2 files changed

+20
-24
lines changed

packages/grpc-js/src/server.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,8 +1384,7 @@ export class Server {
13841384

13851385
let connectionAgeTimer: NodeJS.Timeout | null = null;
13861386
let connectionAgeGraceTimer: NodeJS.Timeout | null = null;
1387-
let keepaliveTimeout: NodeJS.Timeout | null = null;
1388-
let keepaliveDisabled = false;
1387+
let keepaliveTimer: NodeJS.Timeout | null = null;
13891388
let sessionClosedByServer = false;
13901389

13911390
const idleTimeoutObj = this.enableIdleTimeout(session);
@@ -1429,15 +1428,15 @@ export class Server {
14291428
}
14301429

14311430
const clearKeepaliveTimeout = () => {
1432-
if (keepaliveTimeout) {
1433-
clearTimeout(keepaliveTimeout);
1434-
keepaliveTimeout = null;
1431+
if (keepaliveTimer) {
1432+
clearTimeout(keepaliveTimer);
1433+
keepaliveTimer = null;
14351434
}
14361435
};
14371436

14381437
const canSendPing = () => {
14391438
return (
1440-
!keepaliveDisabled &&
1439+
!session.destroyed &&
14411440
this.keepaliveTimeMs < KEEPALIVE_MAX_TIME_MS &&
14421441
this.keepaliveTimeMs > 0
14431442
);
@@ -1453,11 +1452,11 @@ export class Server {
14531452
this.keepaliveTrace(
14541453
'Starting keepalive timer for ' + this.keepaliveTimeMs + 'ms'
14551454
);
1456-
keepaliveTimeout = setTimeout(() => {
1455+
keepaliveTimer = setTimeout(() => {
14571456
clearKeepaliveTimeout();
14581457
sendPing();
14591458
}, this.keepaliveTimeMs);
1460-
keepaliveTimeout.unref?.();
1459+
keepaliveTimer.unref?.();
14611460
};
14621461

14631462
sendPing = () => {
@@ -1501,14 +1500,14 @@ export class Server {
15011500
return;
15021501
}
15031502

1504-
keepaliveTimeout = setTimeout(() => {
1503+
keepaliveTimer = setTimeout(() => {
15051504
clearKeepaliveTimeout();
15061505
this.keepaliveTrace('Ping timeout passed without response');
15071506
this.trace('Connection dropped by keepalive timeout');
15081507
sessionClosedByServer = true;
15091508
session.close();
15101509
}, this.keepaliveTimeoutMs);
1511-
keepaliveTimeout.unref?.();
1510+
keepaliveTimer.unref?.();
15121511
};
15131512

15141513
maybeStartKeepalivePingTimer();
@@ -1528,7 +1527,6 @@ export class Server {
15281527
clearTimeout(connectionAgeGraceTimer);
15291528
}
15301529

1531-
keepaliveDisabled = true;
15321530
clearKeepaliveTimeout();
15331531

15341532
if (idleTimeoutObj !== null) {
@@ -1575,7 +1573,6 @@ export class Server {
15751573
let connectionAgeTimer: NodeJS.Timeout | null = null;
15761574
let connectionAgeGraceTimer: NodeJS.Timeout | null = null;
15771575
let keepaliveTimeout: NodeJS.Timeout | null = null;
1578-
let keepaliveDisabled = false;
15791576
let sessionClosedByServer = false;
15801577

15811578
const idleTimeoutObj = this.enableIdleTimeout(session);
@@ -1626,7 +1623,7 @@ export class Server {
16261623

16271624
const canSendPing = () => {
16281625
return (
1629-
!keepaliveDisabled &&
1626+
!session.destroyed &&
16301627
this.keepaliveTimeMs < KEEPALIVE_MAX_TIME_MS &&
16311628
this.keepaliveTimeMs > 0
16321629
);
@@ -1734,7 +1731,6 @@ export class Server {
17341731
clearTimeout(connectionAgeGraceTimer);
17351732
}
17361733

1737-
keepaliveDisabled = true;
17381734
clearKeepaliveTimeout();
17391735

17401736
if (idleTimeoutObj !== null) {

packages/grpc-js/src/transport.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class Http2Transport implements Transport {
113113
/**
114114
* Timer reference indicating when to send the next ping or when the most recent ping will be considered lost.
115115
*/
116-
private keepaliveTimeout: NodeJS.Timeout | null = null;
116+
private keepaliveTimer: NodeJS.Timeout | null = null;
117117
/**
118118
* Indicates that the keepalive timer ran out while there were no active
119119
* calls, and a ping should be sent the next time a call starts.
@@ -416,7 +416,7 @@ class Http2Transport implements Transport {
416416
this.pendingSendKeepalivePing = true;
417417
return;
418418
}
419-
if (this.keepaliveTimeout) {
419+
if (this.keepaliveTimer) {
420420
console.error('keepaliveTimeout is not null');
421421
return;
422422
}
@@ -426,11 +426,11 @@ class Http2Transport implements Transport {
426426
this.keepaliveTrace(
427427
'Sending ping with timeout ' + this.keepaliveTimeoutMs + 'ms'
428428
);
429-
this.keepaliveTimeout = setTimeout(() => {
429+
this.keepaliveTimer = setTimeout(() => {
430430
this.keepaliveTrace('Ping timeout passed without response');
431431
this.handleDisconnect();
432432
}, this.keepaliveTimeoutMs);
433-
this.keepaliveTimeout.unref?.();
433+
this.keepaliveTimer.unref?.();
434434
let pingSendError = '';
435435
try {
436436
const pingSentSuccessfully = this.session.ping(
@@ -471,14 +471,14 @@ class Http2Transport implements Transport {
471471
if (this.pendingSendKeepalivePing) {
472472
this.pendingSendKeepalivePing = false;
473473
this.maybeSendPing();
474-
} else if (!this.keepaliveTimeout) {
474+
} else if (!this.keepaliveTimer) {
475475
this.keepaliveTrace(
476476
'Starting keepalive timer for ' + this.keepaliveTimeMs + 'ms'
477477
);
478-
this.keepaliveTimeout = setTimeout(() => {
478+
this.keepaliveTimer = setTimeout(() => {
479479
this.maybeSendPing();
480480
}, this.keepaliveTimeMs);
481-
this.keepaliveTimeout.unref?.();
481+
this.keepaliveTimer.unref?.();
482482
}
483483
/* Otherwise, there is already either a keepalive timer or a ping pending,
484484
* wait for those to resolve. */
@@ -488,9 +488,9 @@ class Http2Transport implements Transport {
488488
* Clears whichever keepalive timeout is currently active, if any.
489489
*/
490490
private clearKeepaliveTimeout() {
491-
if (this.keepaliveTimeout) {
492-
clearTimeout(this.keepaliveTimeout);
493-
this.keepaliveTimeout = null;
491+
if (this.keepaliveTimer) {
492+
clearTimeout(this.keepaliveTimer);
493+
this.keepaliveTimer = null;
494494
}
495495
}
496496

0 commit comments

Comments
 (0)