Technical Inquiry: Intermittent WebSocket Disconnections in Multiplayer Card Game
hundrill
HOBBYOP

a month ago

I am a developer currently hosting a NestJS-based card game server on Railway using a Hobby plan. I am reaching out to seek your technical insight regarding intermittent WebSocket disconnection issues.

Issue Description:

  • Environment: NestJS server (Socket.io) with Unity client.

  • Problem: Connections are stable with 2 players, but disconnections occur occasionally when the player count increases to around 5.

  • Observations: * Stress tests with high packet loads do not immediately trigger disconnections.

    • The server is located in the Singapore region, while clients are testing from South Korea via Wi-Fi and mobile data.

I would like to inquire about the following:

  1. Plan Capacity: Could the resource limits (CPU/RAM) of the Hobby plan be causing the server to drop connections under a 5-player load, even if the traffic isn't exceptionally high? Would upgrading to a Pro plan likely resolve this?

  2. Network Stability: Since there is a significant geographical distance between the server (Singapore) and clients (Korea), could the international network route be causing TCP timeouts for WebSocket frames?

  3. Infrastructure Settings: Are there any specific Railway-side configurations (e.g., proxy timeouts or load balancer settings) that might affect long-lived WebSocket connections?

I am eager to resolve this to provide a seamless experience for my players. Any advice or logs you could share regarding these disconnections would be greatly appreciated.

Thank you for your time and for providing a great platform.

Best regards,

This inquiry was drafted with the assistance of AI.

Solved$10 Bounty

Pinned Solution

lu4p
FREETop 10% Contributor

a month ago

Websockets may disconnect for a number of reasons especially in real world long running scenarios. Use this guide to fix it.

https://socket.io/docs/v4/connection-state-recovery

2 Replies

lu4p
FREETop 10% Contributor

a month ago

Websockets may disconnect for a number of reasons especially in real world long running scenarios. Use this guide to fix it.

https://socket.io/docs/v4/connection-state-recovery


hundrill
HOBBYOP

20 days ago

Hi lu4p, thank you for your response!

I’ve carefully reviewed the Connection State Recovery feature in Socket.io v4 that you suggested. To get straight to the point, this was exactly the right direction to solve the intermittent connection issues I was facing.

The ability for the server to maintain the socket state (keeping the socket in the room, etc.) and buffer any missed packets while the client is disconnected is impressive. It allows the client to resume exactly where they left off upon reconnection, without the need for manual room re-entry or complex state synchronization.

However, I hit a major roadblock. For this feature to work, it’s mandatory that the client-side library also supports this specific recovery protocol to "negotiate" the state restoration with the server. Unfortunately, I was unable to find any Unity (C#) Socket.io library that fully supports this v4-specific feature yet.

Due to these limitations in the available client-side libraries for Unity, I have had to set this approach aside for now.

If anyone knows of a Unity/C# Socket.io library that officially supports or has implemented the v4 Connection State Recovery, please let me know. Sharing that information would make this thread incredibly valuable for other Unity developers facing similar challenges.

Thank you again for sharing such a great technical insight!

This response was drafted with the assistance of AI.

Tip: If you decide to post this, it clearly communicates that you understood the solution but are limited by the current Unity ecosystem (the lack of a fully compliant v4/v5 C# client). It invites the community to provide a specific tool, which is a great way to get a follow-up answer!


Status changed to Solved ray-chen 20 days ago


Loading...