Skip to content

Commit

Permalink
grpc-js: Handle errors when trying to ping
Browse files Browse the repository at this point in the history
  • Loading branch information
murgatroid99 committed Aug 8, 2022
1 parent 586f7c6 commit 31d28b5
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions packages/grpc-js/src/subchannel.ts
Expand Up @@ -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() {
Expand Down

0 comments on commit 31d28b5

Please sign in to comment.