Experiencing intermittent client disconnections

  1. Versions: Nakama {3.23.0}, {unity client SDK: v3.13.0}
  2. Server Framework Runtime language {Go}
  3. Unity Version 2022.3.36f1
  4. Server tick rate 25

Issue: Experiencing intermittent client disconnections and server-side logs indicate that clients are being forcibly disconnected with the message "server/session_ws.go:520, Closed client connection.

Game Play: 4 player server authoritative match, racing game with a max match duration of 2 min.
Despite testing in controlled env with good internet connection and good ping (below 60), the issue occurs across WebGL, Android, and iOS platforms.

This is causing significant disruptions to gameplay.

Any advice or suggestions would be really helpful in resolving the issue.

Hello @surajTLabs,

The client should receive a reason of why the server has closed the connection, perhaps it can help diagnose the issue.

I am using ISocket.Closed event on unity client side to detect the disconnection but this event don’t provide any argument/reason…

I must be missing something, please suggest how to get disconnection reason?

@surajTLabs the log line you pointed at just indicates that the socket was closed, it doesn’t necessarily mean that the socket was terminated by the server.

Are there no other potentially interesting logs from the server?

@sesposito Unfortunately, we don’t have any other related useful info… and also from Unity side we are sure that client didn’t closed or disconnected itself…

Is there a way to know socket was closed from client side or server side and what was the reason behind?

Adding an EventSessionEnd handler that logs the event may help you debug - the Event will contain a property string with key reason that could give you more insight on why a socket is being closed.

Thank you, I will implement this and revert with results

In main.go I have added following event

func eventSessionEnd(ctx context.Context, logger runtime.Logger, evt *api.Event) {
	logger.Info("Session End:%+v", evt)
}

and receiving following

{“level”:“info”,“ts”:“2024-11-20T08:29:40.594Z”,“caller”:“game-server/main.go:495”,“msg”:"Session End:name:"session_end" properties:{key:"reason" value:"read tcp 172.31.21.89:7350->172.31.38.90:27224: i/o timeout"}

The client has a stable and reliable internet connection. The game is deployed on WebGL, and the user was playing it using the Chrome browser.

That seems to be a network issue or maybe some network operation that took too long, we’re not aware of any issue with our latest SDKs or Nakama that would explain it, I’m afraid there’s not much more help we can give without more insight and access to your deployment and client code.

It seems like even though match duration is only 120 sec, but to tackle this issue, we need to implement seamless reconnection and rejoining logic