Fix SSE connection closing prematurely for non-existent rooms

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 <noreply@anthropic.com>
This commit is contained in:
2025-12-26 14:03:06 -08:00
parent 50deaeae96
commit 9feb17b734

View File

@@ -93,23 +93,14 @@ function handleStream() {
sendError('Missing room name', 400); 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 // Set SSE headers
header('Content-Type: text/event-stream'); header('Content-Type: text/event-stream');
header('Cache-Control: no-cache'); header('Cache-Control: no-cache');
header('X-Accel-Buffering: no'); // Disable nginx buffering 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 // Track last known count
$lastCount = 0; $lastCount = 0;