grpc session ping when session is destoryed by server
Problem description
When a session call ping, if the session is destoryed by the server. it will throw an error. Error [ERR_HTTP2_INVALID_SESSION]: The session has been destroyed at new NodeError (internal/errors.js:322:7) at ClientHttp2Session.ping (internal/http2/core.js:1317:13) at Subchannel.sendPing (D:\app\node_modules@grpc\grpc-js\src\subchannel.ts:367:19) at Timeout._onTimeout (D:\app\node_modules@grpc\grpc-js\src\subchannel.ts:376:12) at listOnTimeout (internal/timers.js:557:17) at processTimers (internal/timers.js:500:7)
How about to check session!.destroyed first?
private sendPing() {
if (this.session!.destroyed) {
this.keepaliveTrace('Session was destroyed');
this.handleDisconnect();
return;
}
if (this.channelzEnabled) {
this.keepalivesSent += 1;
}
this.keepaliveTrace('Sending ping with timeout ' + this.keepaliveTimeoutMs + 'ms');
this.keepaliveTimeoutId = setTimeout(() => {
this.keepaliveTrace('Ping timeout passed without response');
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);
}
);
}
This should be fixed in version 1.6.9. Please try it out.
Thx @murgatroid99 , we'll try it out.
@murgatroid99, we have applied the version to our production environment and monitor one more week, no such issue happened again. Please close the issue.