grpc-node icon indicating copy to clipboard operation
grpc-node copied to clipboard

grpc session ping when session is destoryed by server

Open zhtswang opened this issue 3 years ago • 3 comments

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)

zhtswang avatar Jun 16 '22 09:06 zhtswang

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);
      }
    );
  }

emmansun avatar Aug 02 '22 03:08 emmansun

This should be fixed in version 1.6.9. Please try it out.

murgatroid99 avatar Aug 09 '22 17:08 murgatroid99

Thx @murgatroid99 , we'll try it out.

emmansun avatar Aug 15 '22 01:08 emmansun

@murgatroid99, we have applied the version to our production environment and monitor one more week, no such issue happened again. Please close the issue.

zhtswang avatar Sep 05 '22 02:09 zhtswang