-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Keep alive is slowing down shutdown #1959
Comments
PR opened: #1960 |
@cschreib-ibex thanks for the report. The reason why I removed I acknowledged the shutdown problem that you mentioned. I am not going to merge #1960, since it uses |
I'm surprised that |
@cschreib-ibex I resolve this issue at e0ebc43. The new implementation of Could you please test this latest version on your project? If it works, I'll bump the cpp-httplib version to 0.18.1. Thanks for your help! |
It works, thank you! PS: I'm still interesting in learning how to run the benchmarks, in case I need to propose another patch in the future. |
Problem
We have an application running an HTTP server, which also ships web pages which regularly send
GET
requests to the server, to update the page content.The application often needs to be "soft-restarted" (the application's process stays alive, but most of the classes are destroyed and re-created, including the HTTP server). When this happens, we are seeing long delays in shutting down the HTTP server, up to a few seconds.
I have traced it down to the "keep alive" logic, which possibly waits for the full duration configured in
CPPHTTPLIB_KEEPALIVE_TIMEOUT_SECOND
before giving up and letting the server shutdown. I believe the issue is essentially that the "keep alive" wait cannot be interrupted by the shutdown:cpp-httplib/httplib.h
Lines 3256 to 3271 in 131bc6c
Here,
select_read()
will block for up tokeep_alive_timeout_sec
, even when the server socket is closed, because the conditionsvr_sock != INVALID_SOCKET
is only checked before starting the call toselect_read()
, and not inside.A possibly better implementation:
I see there used to be a
keep_alive()
function that looked similar (but still wasn't checking forsvr_sock
), and that was removed in 978a4f6. I lack the context to understand why that was done, but the implementation above passed all the tests.How to reproduce
Output I get:
C++ code:
The text was updated successfully, but these errors were encountered: