Enforce a minimum SSE reconnect wait to avoid a busy loop

SSEClient::wait_for_reconnect() sleeps in 100ms steps until the
reconnect interval has elapsed. With an interval of 0 (for example
"retry: 0" from the server, or set_reconnect_interval(0)) it never
slept at all, so a server that sends "retry: 0" and closes the stream
made the client reconnect in a tight loop. set_max_reconnect_attempts()
does not stop this either, because each successful connection resets
the attempt counter.

Always wait at least one step (100ms). Intervals of 1-99ms already
waited 100ms because of the step size, so only 0 and negative values
change behavior.
This commit is contained in:
yhirose
2026-09-28 17:06:51 -04:00
parent 3330d0eb06
commit a96c59780a
3 changed files with 12 additions and 5 deletions
+3
View File
@@ -22702,7 +22702,10 @@ TEST_F(SSEIntegrationTest, DigitRetryFieldApplied) {
std::this_thread::sleep_for(std::chrono::milliseconds(500));
sse.stop();
// The server-supplied interval is applied, but never below 100ms, so
// "retry: 0" does not cause a busy reconnect loop
EXPECT_GE(connection_count.load(), 2);
EXPECT_LE(connection_count.load(), 10);
}
// Test: Last-Event-ID sent on reconnect