From 9feb17b7349b5fce449b17982120f51af5bb0b90 Mon Sep 17 00:00:00 2001 From: Josh Knapp Date: Fri, 26 Dec 2025 14:03:06 -0800 Subject: [PATCH] Fix SSE connection closing prematurely for non-existent rooms MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The server was calling exit() immediately when a room didn't exist, which caused the SSE connection to open and then close right away. This triggered EventSource to reconnect in a loop. Now the server keeps the connection open and sends keepalives even for rooms that don't exist yet. This is the correct SSE behavior - maintain the connection and stream data when it becomes available. Fixes the "connection established then immediately errors" issue seen in diagnostic tests. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- server/php/server.php | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/server/php/server.php b/server/php/server.php index 2f0f2c6..1d3f356 100644 --- a/server/php/server.php +++ b/server/php/server.php @@ -93,23 +93,14 @@ function handleStream() { sendError('Missing room name', 400); } - // Passphrase is optional for streaming (read-only) - // If room doesn't exist yet, return empty stream - if (!roomExists($room)) { - // Return empty stream - room doesn't exist yet - header('Content-Type: text/event-stream'); - header('Cache-Control: no-cache'); - header('X-Accel-Buffering: no'); - echo ": waiting for room to be created\n\n"; - flush(); - exit(); - } - // Set SSE headers header('Content-Type: text/event-stream'); header('Cache-Control: no-cache'); header('X-Accel-Buffering: no'); // Disable nginx buffering + // Passphrase is optional for streaming (read-only) + // If room doesn't exist yet, we'll keep the connection open and wait for it + // Track last known count $lastCount = 0;