connect-es icon indicating copy to clipboard operation
connect-es copied to clipboard

Ping-related error: "session has been destroyed"

Open mpataki opened this issue 1 year ago • 3 comments

Describe the bug

The following error can be thrown when using pings on a grpc transport when the connection is closed:

Unhandled Error: The session has been destroyed
    at new NodeError (node:internal/errors:406:5)
    at ClientHttp2Session.ping (node:internal/http2/core:1377:13)
    at commonPing (/Users/mat/code/syncdna/standalone-app/node_modules/@connectrpc/connect-node/dist/esm/http2-session-manager.js:429:14)
    at Timeout.onPingInterval [as _onTimeout] (/Users/mat/code/syncdna/standalone-app/node_modules/@connectrpc/connect-node/dist/esm/http2-sessi
on-manager.js:422:9)
    at listOnTimeout (node:internal/timers:573:17)
    at processTimers (node:internal/timers:514:7)

To Reproduce

Setup a grpc transport and use it for long lived streaming.

  myTransport = createGrpcTransport({
    baseUrl: myGrpcBaseUrl,
    httpVersion: '2',
    pingIdleConnection: true,
    pingIntervalMs: 5000,
    pingTimeoutMs: 5000,
  });

Environment:

  • @connectrpc/connect version: 1.4.0
  • @connectrpc/connect-node version: 1.4.0
  • Node.js version: 20.12.2

Additional context

Speculation: If a stream cancellation happens, it looks like some race condition can result in the ping task executing against a closed http/2 session, causing the error. Just before the error I often see messages like:

> [MY-RPC-METHOD] [canceled] http/2 stream closed with error code CANCEL (0x8)

mpataki avatar Jul 11 '24 16:07 mpataki

Looks like one way to avoid this is to just check for the destroyed flag.

srikrsna-buf avatar Jul 11 '24 17:07 srikrsna-buf

@srikrsna-buf I presume your comment is a note on how to fix this issue internally to the connect-es library. Yeah?

mpataki avatar Jul 22 '24 12:07 mpataki

@srikrsna-buf following up here

mpataki avatar Aug 30 '24 13:08 mpataki

Hey! I can't seem to reproduce this error. How often are you seeing this? Can you share a runnable code that can reproduce the error?

srikrsna-buf avatar Sep 03 '24 11:09 srikrsna-buf

Thanks for looking at this again. At present I don't have the time, unfortunately just too much going on in my world right now. But I'll get back to this in time and get sometime to you.

mpataki avatar Sep 17 '24 19:09 mpataki

Closing, but please feel free to re-open with a reproducible example.

timostamm avatar Oct 17 '24 12:10 timostamm