From a5ba7d186a936fa8a91c80311a1450bf41eaf5b0 Mon Sep 17 00:00:00 2001 From: Tobias Wilken Date: Fri, 14 Aug 2026 21:24:16 +0200 Subject: [PATCH] Enable TCP keepalive on client socket Chromecasts silently drop idle connections. Without SO_KEEPALIVE the OS never probes, and the next write hangs until the caller's own timeout fires. setKeepAlive(true, 10000) lets the OS detect dead peers after ~10s of TCP-level idle. --- lib/client.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/client.js b/lib/client.js index 786eae6..ae97170 100644 --- a/lib/client.js +++ b/lib/client.js @@ -40,6 +40,11 @@ Client.prototype.connect = function(options, callback) { self.emit('connect'); }); + // Chromecasts silently drop idle connections. Without SO_KEEPALIVE + // the OS never probes, so a dead socket looks alive until the next + // write hangs on the caller's own timeout. + this.socket.setKeepAlive(true, 10000); + this.socket.on('error', onerror); this.socket.once('close', onclose);