Report this

What is the reason for this report?

Websocket server hosted on a VM keeps dropping websocket sonnections to peers after random time intervals

Posted on November 19, 2025

I have a server hosted on a digital ocean droplet running ubuntu. 2 GB Memory / 50 GB Disk / SFO2 - Ubuntu 25.04 x64

The server is built using docker and runs off of the VM on a container with a traefik server that acts as the reverse proxy connecting to the backend server. Ports are open on 8080 and are correctly configured for the client because it does connect and is able to transmit data for a while. No firewalls just yet.

The server communicates with clients sending data and messages. The connection only holds for 30s - 5 minutes at most and then it drops with the message.

11/19/2025 17:01:53|Fatal|WebSocket.<startReceiving>b__176_2|System.ObjectDisposedException: Cannot access a disposed object.
                          Object name: 'System.Net.Sockets.NetworkStream'.
                             at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
                             at WebSocketSharp.Ext.<>c__DisplayClass48_0.<ReadBytesAsync>b__0(IAsyncResult ar)

I tried creating a barebones server and client project with similar set and the same issue occurs. Connect to remote on client -> wait -> (Client)“Receive failed: The remote party closed the WebSocket connection without completing the close handshake.”

Is digital ocean network cutting out and disposing of network connections? Is there any way to hold longer connections? If anyone uses similar configurations I would really appretiate the help as I am fairly new to remote hosting on servers.



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi there,

It’s very unlikely that DigitalOcean is closing your WebSocket connections. Droplets don’t enforce any idle timeout on long-lived TCP streams, so a WebSocket shouldn’t drop on its own. When connections fall after 30 seconds to a few minutes, it’s usually something in the app stack rather than the network.

Since you’re seeing ObjectDisposedException coming from NetworkStream, that often happens when the WebSocket server or reverse proxy closes the connection internally. Traefik is a common place to look first. It has its own connection and idle timeouts, and if those are too low, the proxy will quietly drop the WebSocket even though the droplet itself isn’t doing anything. Checking the Traefik forwardingTimeouts, readTimeout, or idleTimeout is a good start:

https://doc.traefik.io/traefik/v1.7/configuration/commons/

Your WebSocket library can also play a role. WebSocketSharp will dispose the stream if it doesn’t receive ping/pong frames in time or if an internal exception happens during reads. Some people work around this by sending regular pings from the server.

Since your barebones test also disconnects the same way, that points even more toward Traefik or your WebSocket implementation rather than DigitalOcean’s network. If the issue continues after adjusting proxy and app-level timeouts, it’s worth opening a DigitalOcean support ticket with your droplet ID so the team can take a quick look at the network path and confirm everything is healthy.

Heya,

One good way to narrow it down is to temporarily bypass Traefik and connect directly to the backend container on a high port. If those WebSocket connections stay up much longer, you’ve basically confirmed the proxy is the culprit.

If they still drop, look at the app/container itself: check for memory pressure or restarts (docker stats, docker ps --no-trunc), and enable more verbose logging around your WebSocket open/close events. It’s also worth turning on ping/pong at a short interval (e.g. 15–30 seconds) so intermediaries treat the connection as active and you get clearer logs when something times out.

Hope that this helps!

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.