WebSocket DAT random and rapid disconnection on Windows 11

Hello,

Running Windows 11 and TouchDesigner build 2023.12230.

Using a WebSocket DAT connected to a local WebSocket Server (running on Node LTS 20.15, created using the ws library latest version as of 2025-05-28). The server is sending Stringified JSON objects.

The problem:
The WebSocket DAT will unexpectedly disconnect, even when no messages are being received. Pings are received and responded to without disconnecting (logging verifies this).

Using an Info DAT, I see “connected” go from 1 to 0.
By checking if the “Active” parameter is True or False in the onDisconnect callback, I can “force” a reconnection by pulsing the reset parameter.

N.B. I do not encounter this problem on a MacBook Pro, M3 Pro, Sonoma 14.7.5 running TouchDesigner build 2023.12230 (same build).

I’ve seen a few posts lately (March 17 last reply) that seem like they may be similar.

Currently looking to run this build and project on a live show next Tuesday, so any advice is appreciated :slight_smile:

Additional context:

  • The server is not forcing the client to disconnect
  • The server is running on the same computer (ws://localhost, using port 7878)
  • I’ve tried “Connection Timeout” values from the default all the way up to 30 seconds; this doesn’t seem to be related to that (which I recall was a previous issue with disconnections)
  • The Info DAT is now listing errors (2 so far), which is not equal to the number of disconnects occurring, not seeing the errors appear anywhere (looking in the Textport)
  • Disconnects occur every 3-6 seconds, easily, and often “back to back” after I force the reconnection (even with a back-off or delay, on a fresh initial connection I can be disconnected as quickly as 5 seconds fairly often)
  • Info DAT’s “connected” goes to 0, but the WebSocket DAT’s “Active” par is still “On”. (This is how I’m checking the intentional vs. unintentional disconnect to reset, mentioned above)

Cheers.

Additional testing:

  • Rapid/unpredictable disconnection on Windows 11 computer’s WebSocket DAT still occurs when the server is run on a different computer (the non-disconnecting MBP mentioned above)

Do you only experience the issue with your node.js server, or with other servers as well (eg. Web Server DAT)? What exactly is being sent from the server? Does changing what is sent have any impact on the disconnections?

We’ll try and reproduce locally to get to the bottom of this.

I have only reproduced it with my NodeJS server (ws library, more or less the standard), not happening on MacOS Sonoma; is happening on Windows 11.

Disconnects occur even when not actively sending any messages over the connection, just “idling”.

I ran my simple WebSocket Node.js server for about an hour today and so far I’ve been unable to reproduce. Do the disconnects start right away or do you need to run the project/server for a certain amount of time first?

I’m using Node.js version 22.16.0 which I’m not sure makes a difference, but may be worthwhile for you to try upgrading.

Could you attach your Node.js server script so I can more easily replicate your exact set-up?

My systems are on Node 20.xx (previous LTS version), I can try upgrading when I’m back at that machine. Notably it doesn’t happen on macOS with the exact same node version, same WS library version. The disconnects happen immediately on fresh startup of both project or server script.

Here’s the relevant code for the WSS:

import { WebSocketServer } from 'ws';

const wss = new WebSocketServer({ port: port });

function heartbeat() {
  this.isAlive = true;
}

console.log(`Starting new WebSocketServer on port ${port}`);
setInterval(() => console.log(`# of clients: ${wss.clients.size}`), 3000);

wss.on("connection", (ws) => {
  ws.isAlive = true;
  ws.on("error", (e) => console.error(e));
  ws.on("pong", heartbeat);
  ws.on("message", (data) => console.log("Received %s", data));
  ws.on("open", () => console.log("Connection opened"));
  ws.on("close", () => console.log("Connection closed"));
  ws.on("unexpected-response", () => console.log("Unexpected response"));
});

const hbInterval = setInterval(() => {
  wss.clients.forEach((ws) => {
    if (ws.isAlive === false) { 
	console.log("Terminating ws because isAlive is false");
	return ws.terminate();
    }
    ws.isAlive = false;
    ws.ping();
  });
}, 30000);

wss.on("close", () => clearInterval(hbInterval));

Note that the code block has scroll behavior and is hiding the end of the code by default on my screen :grin:

And doing some testing with a tried-and-true connection to Twitch IRC chat via the WebSocket DAT, we’re seeing a similar automatic disconnection behavior, so this leads me to further believe it’s from this version of TouchDesigner or Windows 11, or some interaction between them.

What does your WebSocket DAT callback script look like?

I’m still unable to reproduce locally, unless I remove the pong from the onReceivePing callback, since the server is configured to close the connection after 30 seconds when no pong is received. But you mentioned in your first post the pong is received on the server side so that shouldn’t be the issue.

Also, what is output from the server when the client disconnect occurs?