Merge pull request #1612 from murgatroid99/grpc-js_keepalive_without_calls

grpc-js: Add support for grpc.keepalive_permit_without_calls channel arg
This commit is contained in:
Michael Lumish 2020-10-29 13:21:33 -07:00 committed by GitHub
commit 1612bf0bae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 2 deletions

View File

@ -36,6 +36,7 @@ In addition, all channel arguments defined in [this header file](https://github.
- `grpc.default_authority`
- `grpc.keepalive_time_ms`
- `grpc.keepalive_timeout_ms`
- `grpc.keepalive_permit_without_calls`
- `grpc.service_config`
- `grpc.max_concurrent_streams`
- `grpc.initial_reconnect_backoff_ms`

View File

@ -25,6 +25,7 @@ export interface ChannelOptions {
'grpc.default_authority'?: string;
'grpc.keepalive_time_ms'?: number;
'grpc.keepalive_timeout_ms'?: number;
'grpc.keepalive_permit_without_calls'?: number;
'grpc.service_config'?: string;
'grpc.max_concurrent_streams'?: number;
'grpc.initial_reconnect_backoff_ms'?: number;
@ -49,6 +50,7 @@ export const recognizedOptions = {
'grpc.default_authority': true,
'grpc.keepalive_time_ms': true,
'grpc.keepalive_timeout_ms': true,
'grpc.keepalive_permit_without_calls': true,
'grpc.service_config': true,
'grpc.max_concurrent_streams': true,
'grpc.initial_reconnect_backoff_ms': true,

View File

@ -180,6 +180,10 @@ export class Subchannel {
* Timer reference tracking when the most recent ping will be considered lost
*/
private keepaliveTimeoutId: NodeJS.Timer;
/**
* Indicates whether keepalive pings should be sent without any active calls
*/
private keepaliveWithoutCalls: boolean = false;
/**
* Tracks calls with references to this subchannel
@ -226,6 +230,11 @@ export class Subchannel {
if ('grpc.keepalive_timeout_ms' in options) {
this.keepaliveTimeoutMs = options['grpc.keepalive_timeout_ms']!;
}
if ('grpc.keepalive_permit_without_calls' in options) {
this.keepaliveWithoutCalls = options['grpc.keepalive_permit_without_calls'] === 1;
} else {
this.keepaliveWithoutCalls = false;
}
this.keepaliveIntervalId = setTimeout(() => {}, 0);
clearTimeout(this.keepaliveIntervalId);
this.keepaliveTimeoutId = setTimeout(() => {}, 0);
@ -532,6 +541,9 @@ export class Subchannel {
listener();
}
});
if (this.keepaliveWithoutCalls) {
this.startKeepalivePings();
}
break;
case ConnectivityState.CONNECTING:
this.startBackoff();
@ -602,7 +614,9 @@ export class Subchannel {
if (this.session) {
this.session.ref();
}
this.startKeepalivePings();
if (!this.keepaliveWithoutCalls) {
this.startKeepalivePings();
}
}
this.callRefcount += 1;
}
@ -620,7 +634,9 @@ export class Subchannel {
if (this.session) {
this.session.unref();
}
this.stopKeepalivePings();
if (!this.keepaliveWithoutCalls) {
this.stopKeepalivePings();
}
this.checkBothRefcounts();
}
}