Skip to content

bug: PING sent twice when keepAlive is enabled in fastifyTRPCPlugin #7502

Closed

Description

@01101101

Provide environment information

Not needed.

Describe the bug

‎fastifyTRPCPlugin calls ‎handleKeepAlive when trpcOptions?.keepAlive?.enabled is true.

But fastifyTRPCPlugin also calls getWSConnectionHandler, which again calls handleKeepAlive if opts.keepAlive?.enabled is true.

So the handler is called twice and 2 PING messages are sent each time.

Link to reproduction

Not needed.

To reproduce

Enable keepAlive in fastifyTRPCPlugin.

Additional information

No response

👨‍👧‍👦 Contributing

  • 🙋‍♂️ Yes, I'd be down to file a PR fixing this bug!

Activity

  1. pri12ya871 commented on Aug 29, 2026

    @pri12ya871
    Contributor

    Confirmed on main — the two registrations are:

    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.

  2. webdevsamran commented on Sep 6, 2026

    @webdevsamran

    Hi team, I would like to take this bug fix up.

    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.

    Could you please assign this to me? Thanks!

  3. github-actions commented on Oct 21, 2026

    @github-actions
    Contributor

    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.

  4. locked as resolved and limited conversation to collaborators on Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions