# Socket disconnecting throwing error

**URL:** <https://forum.heroiclabs.com/t/socket-disconnecting-throwing-error/5261>\
**Category:** Client Libraries\
**Tags:** sdk-unity\
**Created:** [May 16, 2024, 8:07am UTC](https://forum.heroiclabs.com/t/socket-disconnecting-throwing-error/5261 "2024-05-16T08:07:40Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![UmarBhatPlaystrom](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/umarbhatplaystrom/32/1635_2.png) [@UmarBhatPlaystrom](https://forum.heroiclabs.com/u/UmarBhatPlaystrom)\
**Post date:** [May 16, 2024, 8:07am UTC](https://forum.heroiclabs.com/t/socket-disconnecting-throwing-error/5261/1 "2024-05-16T08:07:40Z")

</div>

Hi! Recently I started getting an error each time my socket disconnects and I am trying to reconnect.  
As far as I understand `socket.idle_timeout_ms` is a flag in the configuration that is responsible for how long the idle connection can live. That is strange because my lives for 30sec, but in the configuration it is set for 60000ms. That’s the first issue.

The other issue is that when I get disconnected after that timeout of 30sec I get an error:

`System.Net.WebSockets.WebSocketException (0x80004005): The remote party closed the WebSocket connection without completing the close handshake.`

UPD we tested it on our dev nakama environment with the same config and the same version and the error is not being thrown, also socket doesnt get disconnected at all.  
But there is no difference between prod and dev environments

Unity Version: 2021.3.31f1  
Nakama SDK: 3.12.0  
Nakama Server Version: 3.21.1

---

<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:** [May 16, 2024, 2:12pm UTC](https://forum.heroiclabs.com/t/socket-disconnecting-throwing-error/5261/2 "2024-05-16T14:12:53Z")

</div>

Hello @UmarBhatPlaystrom,

The `socket.idle_timeout_ms` refers to how long an HTTP request is kept alive and is not related to websocket connections, I think what you’re looking for is:

```auto
socket.ping_wait_ms
socket.pong_wait_ms

```

Best

---

<div class="post-metadata">

**Author:** ![UmarBhatPlaystrom](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/umarbhatplaystrom/32/1635_2.png) [@UmarBhatPlaystrom](https://forum.heroiclabs.com/u/UmarBhatPlaystrom)\
**Post date:** [May 17, 2024, 9:38am UTC](https://forum.heroiclabs.com/t/socket-disconnecting-throwing-error/5261/3 "2024-05-17T09:38:53Z")

</div>

Nope, they are the same for both dev and prod nakama instances’ configurations

The only thing I did so far is that I found out that if I explicitly set `ISocketAdapter` to `WebSocketAdapter` the exception is not being thrown, but if I set it to `WebSocketStdlibAdapter` (it is set by default) the exception starts to be throw again. In both cases socket is being disconnected every 30 seconds (In dev version nakama instance socket is never being disconnected itself)

While the issue doesnt persist on dev version of nakama

---

<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:** [May 21, 2024, 2:09pm UTC](https://forum.heroiclabs.com/t/socket-disconnecting-throwing-error/5261/4 "2024-05-21T14:09:24Z")

</div>

It’s possible that `WebSocketStdlibAdapter` isn’t handling ping/pong messages correctly under the hood, if you’re not targeting consoles then there’s no downside in using `WebSocketAdapter`.

Are these environments on Heroic Cloud? If yes please contact us at `support@heroiclabs.com` with the project names and we’ll have a look.

---

<div class="post-metadata">

**Author:** ![UmarBhatPlaystrom](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/umarbhatplaystrom/32/1635_2.png) [@UmarBhatPlaystrom](https://forum.heroiclabs.com/u/UmarBhatPlaystrom)\
**Post date:** [May 22, 2024, 11:34am UTC](https://forum.heroiclabs.com/t/socket-disconnecting-throwing-error/5261/5 "2024-05-22T11:34:22Z")

</div>

We use Drone CI. But `WebSocketStdlibAdapter ` is working correct on dev environment. Can you, please, navigate me on where should I look for a problem?

---

<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:** [May 22, 2024, 12:42pm UTC](https://forum.heroiclabs.com/t/socket-disconnecting-throwing-error/5261/6 "2024-05-22T12:42:18Z")

</div>

@lugehorsam perhaps you can help here?

---

<div class="post-metadata">

**Author:** ![lugehorsam](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/lugehorsam/32/314_2.png) [@lugehorsam](https://forum.heroiclabs.com/u/lugehorsam)\
**Post date:** [May 22, 2024, 4:57pm UTC](https://forum.heroiclabs.com/t/socket-disconnecting-throwing-error/5261/7 "2024-05-22T16:57:13Z")

</div>

Hey @UmarBhatPlaystrom this sounds like an issue specific to your infrastructure setup that we cannot assist with. We recommend Heroic Cloud for running Nakama in production.

---

<div class="post-metadata">

**Author:** ![leopthurler](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/leopthurler/32/2641_2.png) [@leopthurler](https://forum.heroiclabs.com/u/leopthurler)\
**Post date:** [September 15, 2025, 7:23pm UTC](https://forum.heroiclabs.com/t/socket-disconnecting-throwing-error/5261/8 "2025-09-15T19:23:19Z")

</div>

Hello @UmarBhatPlaystrom could you solve this problem?  
In localhost all is working right, but when I’m hosting in GCP I can authenticate, start the match but after 30 seconds the player lost the connection.

Defold Client SDK: 3.4.0  
Nakama Server Version: 3.31.1

---

<div class="post-metadata">

**Author:** ![leopthurler](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/leopthurler/32/2641_2.png) [@leopthurler](https://forum.heroiclabs.com/u/leopthurler)\
**Post date:** [September 16, 2025, 4:23pm UTC](https://forum.heroiclabs.com/t/socket-disconnecting-throwing-error/5261/9 "2025-09-16T16:23:11Z")

</div>

I found a way to solve this problem, in my case I’m using Google Kurbenates Engine (GKE) to run a pod with the Nakama server. By default, GKE uses a google default loadbalance technology from the Google Cloud Engine (GCE), and to solve it I change this default loadbalance to use NGINX, and now the players stay connected by hours without problem.
