Skip to content

Commit

Permalink
Merge pull request #2097 from murgatroid99/grpc-js_keepalive_end_calls
Browse files Browse the repository at this point in the history
grpc-js: End calls when keepalive pings time out
  • Loading branch information
murgatroid99 committed Apr 18, 2022
2 parents 432fd95 + cf11b60 commit fa92727
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/grpc-js/package.json
@@ -1,6 +1,6 @@
{
"name": "@grpc/grpc-js",
"version": "1.6.5",
"version": "1.6.6",
"description": "gRPC Library for Node - pure JS implementation",
"homepage": "https://grpc.io/",
"repository": "https://github.com/grpc/grpc-node/tree/master/packages/grpc-js",
Expand Down
18 changes: 11 additions & 7 deletions packages/grpc-js/src/subchannel.ts
Expand Up @@ -358,7 +358,7 @@ export class Subchannel {
this.keepaliveTrace('Sending ping with timeout ' + this.keepaliveTimeoutMs + 'ms');
this.keepaliveTimeoutId = setTimeout(() => {
this.keepaliveTrace('Ping timeout passed without response');
this.transitionToState([ConnectivityState.READY], ConnectivityState.IDLE);
this.handleDisconnect();
}, this.keepaliveTimeoutMs);
this.keepaliveTimeoutId.unref?.();
this.session!.ping(
Expand Down Expand Up @@ -642,6 +642,15 @@ export class Subchannel {
);
}

private handleDisconnect() {
this.transitionToState(
[ConnectivityState.READY],
ConnectivityState.TRANSIENT_FAILURE);
for (const listener of this.disconnectListeners) {
listener();
}
}

/**
* Initiate a state transition from any element of oldStates to the new
* state. If the current connectivityState is not in oldStates, do nothing.
Expand Down Expand Up @@ -672,12 +681,7 @@ export class Subchannel {
const session = this.session!;
session.socket.once('close', () => {
if (this.session === session) {
this.transitionToState(
[ConnectivityState.READY],
ConnectivityState.TRANSIENT_FAILURE);
for (const listener of this.disconnectListeners) {
listener();
}
this.handleDisconnect();
}
});
if (this.keepaliveWithoutCalls) {
Expand Down

0 comments on commit fa92727

Please sign in to comment.