-
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
Sporadically http clients show the error that the server connection has been reset #1870
Comments
I face the same problem getting sporadic // single threaded server
#define CPPHTTPLIB_THREAD_POOL_COUNT 1
#include <httplib.h>
httplib::Server server;
server.set_keep_alive_timeout(0);
// setup endpoints...
server.listen("0.0.0.0", 8080); Any ideas? Edit: I'm using version 0.12.2 |
Looks like a keep-alive problem. I came up with it when I read the issue #1825 which was fixed with disabling keep-alive on the client side. Probably the function process_server_socket_core causes this:
set_keep_alive_timeout (5); // default @yhirose I suggest to increase the default value for keep_alive_max_count_ or at least mention that in the documentation. |
Thank you for the deep dive @RainerSchielke. Following settings seem to work for me: #define CPPHTTPLIB_THREAD_POOL_COUNT 2
#define CPPHTTPLIB_KEEPALIVE_TIMEOUT_SECOND 5
#define CPPHTTPLIB_KEEPALIVE_MAX_COUNT 300 Whenever I switch to a single-threaded server ( |
@RainerSchielke thanks for the report. The documentation already mentions it as below, and I feel it's enough for those who know the HTTP/1.1 Keep-Alive connection spec. https://github.com/yhirose/cpp-httplib?tab=readme-ov-file#keep-alive-connection But of course, any pull request which updates README is welcome! |
Sporadically our java client logs the message "HttpURLConnection.getInputStream java.io.IOException: Error writing to server" which ocurred because the receiving server closed the connection.
Our Windows-http client shows the windows error code 12030, which means "The connection with the server has been reset or terminated"
I increased the receive buffer size to 256k and the number of threads to 64. This reduced the occurence to about once in 1000 requests.
Then I added a retry in my clients, which helped. But I am not happy with that.
Btw. we do not use "keep alive", at server initialization we call set_keep_alive_timeout (0). Without that, every requests delays for 5 seconds.
Why resets the httplib server the connection sporadically ?
The text was updated successfully, but these errors were encountered: