From baf27c59933f0a96072dd124e616a1cc973b4995 Mon Sep 17 00:00:00 2001 From: yhirose Date: Mon, 23 Nov 2026 21:54:21 -0500 Subject: [PATCH] Drop the heartbeat's own closed_ update and the vacuous test check send_frame now marks the connection closed whenever it returns false, so the heartbeat no longer needs to. The second send() in the test fails before the fix too, since the client is not reading, so it does not check anything; large_sent becomes an ASSERT as the precondition. --- httplib.h | 6 +----- test/test.cc | 5 +---- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/httplib.h b/httplib.h index a81bc725..f9a32424 100644 --- a/httplib.h +++ b/httplib.h @@ -25052,11 +25052,7 @@ inline void WebSocket::start_heartbeat() { return; } lock.unlock(); - if (!send_frame(Opcode::Ping, nullptr, 0)) { - lock.lock(); - closed_ = true; - break; - } + if (!send_frame(Opcode::Ping, nullptr, 0)) { return; } lock.lock(); unacked_pings_++; } diff --git a/test/test.cc b/test/test.cc index 31455ba2..eda76134 100644 --- a/test/test.cc +++ b/test/test.cc @@ -29625,7 +29625,6 @@ TEST(WebSocketPartialWriteTest, FailedWriteClosesConnection) { const std::string large(4 * 1024 * 1024, 'A'); std::atomic large_sent{true}; std::atomic open_after_failure{true}; - std::atomic small_sent{true}; std::atomic handler_done{false}; Server svr; @@ -29638,7 +29637,6 @@ TEST(WebSocketPartialWriteTest, FailedWriteClosesConnection) { svr.WebSocket("/ws", [&](const Request &, ws::WebSocket &ws) { large_sent = ws.send(large.data(), large.size()); open_after_failure = ws.is_open(); - small_sent = ws.send("after"); handler_done = true; }); @@ -29665,9 +29663,8 @@ TEST(WebSocketPartialWriteTest, FailedWriteClosesConnection) { } ASSERT_TRUE(handler_done); - EXPECT_FALSE(large_sent); + ASSERT_FALSE(large_sent); EXPECT_FALSE(open_after_failure); - EXPECT_FALSE(small_sent); client.close(); }