grpc-js: Handle errors when trying to ping

This commit is contained in:
Michael Lumish 2022-08-08 13:05:26 -07:00
parent 586f7c6db9
commit 31d28b5f14
1 changed files with 15 additions and 6 deletions

View File

@ -361,12 +361,21 @@ export class Subchannel {
this.handleDisconnect();
}, this.keepaliveTimeoutMs);
this.keepaliveTimeoutId.unref?.();
this.session!.ping(
(err: Error | null, duration: number, payload: Buffer) => {
this.keepaliveTrace('Received ping response');
clearTimeout(this.keepaliveTimeoutId);
}
);
try {
this.session!.ping(
(err: Error | null, duration: number, payload: Buffer) => {
this.keepaliveTrace('Received ping response');
clearTimeout(this.keepaliveTimeoutId);
}
);
} catch (e) {
/* If we fail to send a ping, the connection is no longer functional, so
* we should discard it. */
this.transitionToState(
[ConnectivityState.READY],
ConnectivityState.TRANSIENT_FAILURE
);
}
}
private startKeepalivePings() {