You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bug: PING sent twice when keepAlive is enabled in fastifyTRPCPlugin #7502
so every socket gets two ping intervals and two pong-wait timers, not just the doubled PING — the second timer can also close a connection that the first one already considers healthy.
@01101101 you ticked that you would be up for a PR — are you working on it? Happy to leave it with you. If you would rather not, I will take it.
The fix I would make: drop the direct call in the fastify plugin rather than the one in getWSConnectionHandler, since the shared handler is what every adapter goes through, so keepalive belongs there. I would also check the standalone ws and Next.js adapters for the same double registration and fold those in if present, plus a regression test asserting exactly one PING per interval when keepAlive is enabled.
One question for the maintainers, since this is still labelled unconfirmed: is the plugin-level call intentional for some fastify-specific reason I have missed? If so the fix is the reverse — drop it from the shared handler for this path — and I would rather ask than guess.
In packages/server/src/adapters/fastify/fastifyTRPCPlugin.ts, handleKeepAlive is registered directly and then called again inside getWSConnectionHandler, resulting in duplicate PING messages. I can deduplicate the keep-alive handler initialization so each connection is monitored once, and add regression tests.
This issue has been locked because we are very unlikely to see comments on closed issues. If you are running into a similar issue, please create a new issue. Thank you.
Activity
pri12ya871 commentedon Aug 29, 2026
Confirmed on
main— the two registrations are:fastifyTRPCPlugin.tsL81-L83 callshandleKeepAlive(socket, ...)directlyonConnectionhandler it builds on L75 isgetWSConnectionHandler, which already callshandleKeepAlive(client, ...)at ws.ts L124-L126 whenopts.keepAlive?.enabledso every socket gets two ping intervals and two pong-wait timers, not just the doubled PING — the second timer can also close a connection that the first one already considers healthy.
@01101101 you ticked that you would be up for a PR — are you working on it? Happy to leave it with you. If you would rather not, I will take it.
The fix I would make: drop the direct call in the fastify plugin rather than the one in
getWSConnectionHandler, since the shared handler is what every adapter goes through, so keepalive belongs there. I would also check the standalonewsand Next.js adapters for the same double registration and fold those in if present, plus a regression test asserting exactly one PING per interval whenkeepAliveis enabled.One question for the maintainers, since this is still labelled unconfirmed: is the plugin-level call intentional for some fastify-specific reason I have missed? If so the fix is the reverse — drop it from the shared handler for this path — and I would rather ask than guess.
webdevsamran commentedon Sep 6, 2026
Hi team, I would like to take this bug fix up.
In
packages/server/src/adapters/fastify/fastifyTRPCPlugin.ts,handleKeepAliveis registered directly and then called again insidegetWSConnectionHandler, resulting in duplicate PING messages. I can deduplicate the keep-alive handler initialization so each connection is monitored once, and add regression tests.Could you please assign this to me? Thanks!
fix(server): register keepalive once per websocket connection (trpc#7529
github-actions commentedon Oct 21, 2026
This issue has been locked because we are very unlikely to see comments on closed issues. If you are running into a similar issue, please create a new issue. Thank you.