Bandit websocket server connection terminated reason={:error, :closed}

Hi everyone! :waving_hand:

I’m building a WebSocket server with Bandit inside a Plug app, and the experience has been fantastic so far, really clear semantics and great performance out of the box.

I’ve run into one issue, though: I occasionally see connections terminate with {:error, :closed}. I’m trying to figure out the best way to diagnose what’s causing these closures, since there’s nothing in the server logs that seems to explain them, and our code never returns a {:stop, reason, state}.

Has anyone dealt with this before or have suggestions on how to track down the source of these disconnects?

Thanks in advance!

I was able to capture some additional information using Bandit / Thousand island telemetry.

It turns out the error that is causing those disconnections is:

[:thousand_island, :connection, :send_error]

with

measurements=%{error: :closed, ...}

If this is deployed somewhere, it might be your infrastructure provider not allowing long-lived connections.

1 Like

Yes, that definitely makes sense!

Additionally, in my testing I noticed that some WebSocket clients don’t actually send a close frame or status code when they disconnect, they just close the underlying TCP connection. That was a bit surprising and explains why the server sees it as an abrupt disconnect rather than a regular shutdown, which in turn makes it harder to differentiate network interruptions from regular application-level connection terminations.