From 845492f0b3ceced6d6c9097262bc603848a99353 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Natan=20S=C4=85gol?= Date: Thu, 7 Nov 2019 20:42:33 +0100 Subject: [PATCH 1/2] fix: prevent exceeding timer limitations when backing off --- packages/grpc-js/src/subchannel.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/grpc-js/src/subchannel.ts b/packages/grpc-js/src/subchannel.ts index 3598a9b9..2ef23745 100644 --- a/packages/grpc-js/src/subchannel.ts +++ b/packages/grpc-js/src/subchannel.ts @@ -283,7 +283,7 @@ export class Subchannel { * https://github.com/grpc/proposal/blob/master/A8-client-side-keepalive.md#basic-keepalive */ if (errorCode === http2.constants.NGHTTP2_ENHANCE_YOUR_CALM && opaqueData.equals(tooManyPingsData)) { logging.log(LogVerbosity.ERROR, `Connection to ${this.channelTarget} rejected by server because of excess pings`); - this.keepaliveTimeMs *= 2; + this.keepaliveTimeMs = Math.min(2 * this.keepaliveTimeMs, KEEPALIVE_TIME_MS); } this.transitionToState( [ConnectivityState.CONNECTING, ConnectivityState.READY], From a8d6c8751a53cc699dda4a673692e8e420e824ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Natan=20S=C4=85gol?= Date: Thu, 7 Nov 2019 21:48:35 +0100 Subject: [PATCH 2/2] style: rename KEEPALIVE_TIME_MS to KEEPALIVE_MAX_TIME_MS --- packages/grpc-js/src/subchannel.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/grpc-js/src/subchannel.ts b/packages/grpc-js/src/subchannel.ts index 2ef23745..a52c3477 100644 --- a/packages/grpc-js/src/subchannel.ts +++ b/packages/grpc-js/src/subchannel.ts @@ -44,7 +44,7 @@ const BACKOFF_JITTER = 0.2; /* setInterval and setTimeout only accept signed 32 bit integers. JS doesn't * have a constant for the max signed 32 bit integer, so this is a simple way * to calculate it */ -const KEEPALIVE_TIME_MS = ~(1 << 31); +const KEEPALIVE_MAX_TIME_MS = ~(1 << 31); const KEEPALIVE_TIMEOUT_MS = 20000; export type ConnectivityStateListener = ( @@ -112,7 +112,7 @@ export class Subchannel { /** * The amount of time in between sending pings */ - private keepaliveTimeMs: number = KEEPALIVE_TIME_MS; + private keepaliveTimeMs: number = KEEPALIVE_MAX_TIME_MS; /** * The amount of time to wait for an acknowledgement after sending a ping */ @@ -283,7 +283,7 @@ export class Subchannel { * https://github.com/grpc/proposal/blob/master/A8-client-side-keepalive.md#basic-keepalive */ if (errorCode === http2.constants.NGHTTP2_ENHANCE_YOUR_CALM && opaqueData.equals(tooManyPingsData)) { logging.log(LogVerbosity.ERROR, `Connection to ${this.channelTarget} rejected by server because of excess pings`); - this.keepaliveTimeMs = Math.min(2 * this.keepaliveTimeMs, KEEPALIVE_TIME_MS); + this.keepaliveTimeMs = Math.min(2 * this.keepaliveTimeMs, KEEPALIVE_MAX_TIME_MS); } this.transitionToState( [ConnectivityState.CONNECTING, ConnectivityState.READY],