mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-08-12 21:31:25 +00:00
SocketStream.wait_writable_INET binds PORT + 1 directly, and it was the only raw listener in the file that did not set SO_REUSEPORT/SO_REUSEADDR first. PORT + 1 is shared with three SSL redirect tests and with VulnerabilityTest.CRLFInjectionInHeaders, so once any of those has run, the TIME_WAIT entries they leave make bind() fail here. That failure did not surface where it happened. The bind runs on a worker thread, where a failed ASSERT_EQ only returns from the lambda, so the test carried on and failed later at ASSERT_NE(disconnected_svr_sock, -1) with nothing pointing at the port. Within one run of the suite the test comes before everything that uses PORT + 1, so a clean run passes; it failed when a previous process had left TIME_WAIT behind, which made it look intermittent. Running any of those four tests first and then this one reproduces it every time: 4 of 4 before this change, 4 of 4 passing after, with up to eight TIME_WAIT entries on the port. Call default_socket_options(), which is what the library does for its own listeners and what the other raw listeners in this file already do.