# Experiencing intermittent client disconnections

**URL:** <https://forum.heroiclabs.com/t/experiencing-intermittent-client-disconnections/5774>\
**Category:** Runtime Framework\
**Tags:** sdk-unity, golang, server-framework\
**Created:** [November 4, 2024, 8:24am UTC](https://forum.heroiclabs.com/t/experiencing-intermittent-client-disconnections/5774 "2024-11-04T08:24:46Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![surajTLabs](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/surajtlabs/32/1497_2.png) [@surajTLabs](https://forum.heroiclabs.com/u/surajTLabs)\
**Post date:** [November 4, 2024, 8:24am UTC](https://forum.heroiclabs.com/t/experiencing-intermittent-client-disconnections/5774/1 "2024-11-04T08:24:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sesposito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sesposito/32/2594_2.png) [@sesposito](https://forum.heroiclabs.com/u/sesposito)\
**Post date:** [November 4, 2024, 11:50am UTC](https://forum.heroiclabs.com/t/experiencing-intermittent-client-disconnections/5774/2 "2024-11-04T11:50:41Z")

</div>

Hello @surajTLabs,

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

---

<div class="post-metadata">

**Author:** ![surajTLabs](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/surajtlabs/32/1497_2.png) [@surajTLabs](https://forum.heroiclabs.com/u/surajTLabs)\
**Post date:** [November 4, 2024, 12:32pm UTC](https://forum.heroiclabs.com/t/experiencing-intermittent-client-disconnections/5774/3 "2024-11-04T12:32:22Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![sesposito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sesposito/32/2594_2.png) [@sesposito](https://forum.heroiclabs.com/u/sesposito)\
**Post date:** [November 4, 2024, 2:28pm UTC](https://forum.heroiclabs.com/t/experiencing-intermittent-client-disconnections/5774/4 "2024-11-04T14:28:06Z")

</div>

@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?

---

<div class="post-metadata">

**Author:** ![surajTLabs](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/surajtlabs/32/1497_2.png) [@surajTLabs](https://forum.heroiclabs.com/u/surajTLabs)\
**Post date:** [November 4, 2024, 2:43pm UTC](https://forum.heroiclabs.com/t/experiencing-intermittent-client-disconnections/5774/5 "2024-11-04T14:43:39Z")

</div>

@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?

---

<div class="post-metadata">

**Author:** ![sesposito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sesposito/32/2594_2.png) [@sesposito](https://forum.heroiclabs.com/u/sesposito)\
**Post date:** [November 4, 2024, 4:09pm UTC](https://forum.heroiclabs.com/t/experiencing-intermittent-client-disconnections/5774/6 "2024-11-04T16:09:53Z")

</div>

Adding an [EventSessionEnd](https://heroiclabs.com/docs/nakama/concepts/events/#built-in-events-1) 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.

---

<div class="post-metadata">

**Author:** ![surajTLabs](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/surajtlabs/32/1497_2.png) [@surajTLabs](https://forum.heroiclabs.com/u/surajTLabs)\
**Post date:** [November 4, 2024, 4:22pm UTC](https://forum.heroiclabs.com/t/experiencing-intermittent-client-disconnections/5774/7 "2024-11-04T16:22:38Z")

</div>

Thank you, I will implement this and revert with results

---

<div class="post-metadata">

**Author:** ![surajTLabs](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/surajtlabs/32/1497_2.png) [@surajTLabs](https://forum.heroiclabs.com/u/surajTLabs)\
**Post date:** [November 20, 2024, 8:58am UTC](https://forum.heroiclabs.com/t/experiencing-intermittent-client-disconnections/5774/8 "2024-11-20T08:58:01Z")

</div>

In main.go I have added following event

```auto
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.

---

<div class="post-metadata">

**Author:** ![sesposito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sesposito/32/2594_2.png) [@sesposito](https://forum.heroiclabs.com/u/sesposito)\
**Post date:** [November 21, 2024, 4:36pm UTC](https://forum.heroiclabs.com/t/experiencing-intermittent-client-disconnections/5774/9 "2024-11-21T16:36:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![surajTLabs](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/surajtlabs/32/1497_2.png) [@surajTLabs](https://forum.heroiclabs.com/u/surajTLabs)\
**Post date:** [November 26, 2024, 9:46am UTC](https://forum.heroiclabs.com/t/experiencing-intermittent-client-disconnections/5774/10 "2024-11-26T09:46:29Z")

</div>

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
