Ping-related error: "session has been destroyed"
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)
Looks like one way to avoid this is to just check for the destroyed flag.
@srikrsna-buf I presume your comment is a note on how to fix this issue internally to the connect-es library. Yeah?
@srikrsna-buf following up here
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?
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.
Closing, but please feel free to re-open with a reproducible example.