Skip to content

Commit

Permalink
Merge pull request #2188 from murgatroid99/grpc-js_ping_error_check
Browse files Browse the repository at this point in the history
grpc-js: Handle errors when trying to ping
  • Loading branch information
murgatroid99 committed Aug 8, 2022
2 parents fb8de85 + 31d28b5 commit b08171e
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 b08171e

Please sign in to comment.