# Fix Error WebSocketException When Disconnecting Unity Editor from Server

**URL:** <https://forum.heroiclabs.com/t/fix-error-websocketexception-when-disconnecting-unity-editor-from-server/6468>\
**Category:** Game Design\
**Tags:** sdk-unity\
**Created:** [December 4, 2025, 8:22am UTC](https://forum.heroiclabs.com/t/fix-error-websocketexception-when-disconnecting-unity-editor-from-server/6468 "2025-12-04T08:22:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JoenTNT](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/joentnt/32/2708_2.png) [@JoenTNT](https://forum.heroiclabs.com/u/JoenTNT)\
**Post date:** [December 4, 2025, 8:22am UTC](https://forum.heroiclabs.com/t/fix-error-websocketexception-when-disconnecting-unity-editor-from-server/6468/1 "2025-12-04T08:22:40Z")

</div>

Hi, I have been testing the connection between my Unity Editor and Nakama Server running locally. However I got this error after I disconnecting socket:

```auto
System.Net.WebSockets.WebSocketException (0x80004005): The remote party closed the WebSocket connection without completing the close handshake. ---> System.IO.IOException: Unable to read data from the transport connection: Operation aborted. ---> System.Net.Sockets.SocketException: Operation aborted
   --- End of inner exception stack trace ---

```

This is my Disconnect Function:

```auto
public async void Disconnect()
{
    if (_socket != null)
    {
        if (_socket.IsConnected)
            await _socket.CloseAsync();

        _socket.Connected -= ListenOnSocketConnected;
        _socket.Closed -= ListenOnSocketClosed;

        _socket = null;
    }

    _session = null;
    _client = null;
    _status = NakamaConnectionStatus.Disconnect;
}

```

The error happens while in game, this is what I did:

```auto
1. Connect
2. Disconnect
3. Connect
4. Disconnect -> WebSocketException

```

It seems fine for runtime but I need to know how to fix this or just letting it be and ignore the error.

- I’m using Linux - Fedora 43, Nakama Unity SDK version 3.19.0
- Nakama Server running in local using Docker Compose, version Nakama 3.34.1

Any answer and solution for this issue? I can provide more from my code that I made and currently still working on my game.

#### Thank You!

---

<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:** [December 4, 2025, 11:21am UTC](https://forum.heroiclabs.com/t/fix-error-websocketexception-when-disconnecting-unity-editor-from-server/6468/2 "2025-12-04T11:21:18Z")

</div>

Hi @JoenTNT,

This is just a mishandling of the socket closure handshake, leading to the exception. A fix is already in place in the latest Nakama versions, but I think the related fix in the client hasn’t been released yet.

You can ignore these exceptions when closing the socket.

Best

---

<div class="post-metadata">

**Author:** ![JoenTNT](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/joentnt/32/2708_2.png) [@JoenTNT](https://forum.heroiclabs.com/u/JoenTNT)\
**Post date:** [December 4, 2025, 12:16pm UTC](https://forum.heroiclabs.com/t/fix-error-websocketexception-when-disconnecting-unity-editor-from-server/6468/3 "2025-12-04T12:16:35Z")

</div>

Aight, Much Obliged! Even thought the client connection logic flow has no problem and runs normally, I will ignore this error until next release.

---

<div class="post-metadata">

**Author:** ![JoenTNT](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/joentnt/32/2708_2.png) [@JoenTNT](https://forum.heroiclabs.com/u/JoenTNT)\
**Post date:** [December 30, 2025, 3:45am UTC](https://forum.heroiclabs.com/t/fix-error-websocketexception-when-disconnecting-unity-editor-from-server/6468/4 "2025-12-30T03:45:11Z")

</div>

I have updated to Unity SDK 3.21.0, the error is now gone and it runs with no issue.
