Skip to content

bug(trpc/next): Regression - Subscriptions do not resume if the server closes the connection unexpectedly #5118

@avarayr

Description

@avarayr

Provide environment information

System:
OS: macOS 13.5.2
CPU: (8) x64 Apple M1 Pro
Memory: 12.33 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 18.16.0 - ~/.nvm/versions/node/v18.16.0/bin/node
Yarn: 1.22.19 - ~/.nvm/versions/node/v18.16.0/bin/yarn
npm: 10.1.0 - ~/.nvm/versions/node/v18.16.0/bin/npm
pnpm: 8.7.6 - ~/.nvm/versions/node/v18.16.0/bin/pnpm
Watchman: 2023.08.14.00 - /opt/homebrew/bin/watchman
Browsers:
Chrome: 117.0.5938.88
Safari: 16.6
npmPackages:
@tanstack/react-query: 5.0.0
@trpc/client: next
@trpc/next: next
@trpc/react-query: next
@trpc/server: next
next: ^13.4.8 => 13.5.1
react: ^18.2.0 => 18.2.0
typescript: ^5.1.3 => 5.2.2

Describe the bug

tRPC subscriptions do not automatically resume if the server unexpectedly closes the connection.
This can happen because of various reasons

  • WAF such as Cloudflare will close websocket connections after 100 seconds
  • NGINX will do the same if proxy_read_timeout is set

Looks like there's a regression in the #4959

Link to reproduction

https://github.com/avarayr/trpc-ws-subs-regression

To reproduce

  1. Clone reproduction repository
  2. npm install
  3. npm run dev
  4. Go to https://127.0.0.1:3000
  5. Observe the subscription doesn't restart if the server closes the socket.

Additional information

No response

👨‍👧‍👦 Contributing

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

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