-
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
detail::is_socket_alive() is not work for https connection #1481
Comments
@chisheng thanks for the feedback. This method is not intended to be used by users, rather for internal use in cpp-httplib to detect a current socket is writable. That's why it's in the namespace Also there exist some unit cases where you can see it returns 'false'. One of them is |
Sorry,I didn't explain my problem clearly.Pseudocode |
@chisheng thanks for the more details. I'll try to reproduce it.
Does it actually mean that your server will close within 60 seconds? |
yes,the keep-alive timeout of http server is 60s |
@chisheng I now confirmed it's a bug. Thanks for the report. |
@chisheng I fixed it. Could you try it with the latest httplib.h in your project? |
@chisheng it seems like my fix disable KeepAlive connection completely... Sorry about that. I'll work on it again. |
@chisheng I now fixed it. Could you try the latest httplib.h in the master branch? If it works on your machine, I'll bump up the version number. Thanks! |
Function with provider may be not work ,beacause i find write_request return false,SSL_peek is not executed.and SSL_peek()return 0 mean TLS broken? did not use SSL_get_error() to get error ,I guess SSL_get_error return SSL_ERROR_WANT_READ when The server response delay ,SSL_peek return 0 in this situation. |
@chisheng, thanks for the feedback.
What does it mean by that? If it's not you, could tell the developer to try with the latest httplib.h in the master branch? 0.9.7 is too old, and I don't support it any more.
I can't reproduce the problem on my machine. Could you provide the smallest possible code example or a unit test, so that I can see what's going on? My test case in
Not necessarily though, it's the only way to detect the SSL peer is closed, because when the client succeeds sending a HTTP request, it is supposed to receive a HTTP response according to the HTTP specification. But just in case, I added a code to check the error code from |
Instead of GET request, Mey be use POST requests with both MultipartFormDataItems and ContentProviders can indicate the problem.I will do the test on x86 device using latest version,but it takes some time.Currently I am using this library in the embed arm linux system |
I think the most reasonable way to determine whether the ssl connection is broken by peer is to use the function SSL_ Peek() and SSL_ get_ Shutdown (), just as catboost used. https://github.com/catboost/catboost/blob/master/library/cpp/neh/https.cpp int PollReadT(const TDuration& timeout) {
} In addition, I don't think all compilers can guarantee SSL_ Peek() precedes SSL_ get_ Error () is called,in the following statement. |
Your saying isn't correct. Short-circuiting and evaluation order are required for operators |
Use the following unit test code to reproduce the bug TEST(KeepAliveTest, SSLClientReconnection) { svr.Post("/hi", [](const httplib::Request &, httplib::Response &res) { auto f = std::async(std::launch::async, [&svr] { svr.listen(HOST, PORT); }); SSLClient cli(HOST, PORT); auto result = cli.Post("/hi",content.size(),[&content](size_t offset, size_t length, DataSink &sink){ },"text/plain"); std::this_thread::sleep_for(std::chrono::seconds(2)); // Recoonect
return true; svr.stop(); |
I just tested with your unit test using
|
Do you completely replace my unit test code or you just replace the original unit test get method with the post method? You must use the method with a provider to reproduce it |
Yes, I took your version of |
Strangely, I replaced a computer and still can reproduce this bug.In theory, if you use the request function with the provider parameter, write_ Request() returns false, resulting in SSL_ Peek() cannot be executed. if (!write_request(strm, req, close_connection, error)) { return false; }//returned ,when call Post() with provider parameter,write_ Request() returns false #ifdef CPPHTTPLIB_OPENSSL_SUPPORT chisheng@chisheng-EQ59:~/code/cpp-httplib/test$ make test && ./test --gtest_filter="SSLClientReconnection" |
This now should be fixed. |
is_socket_alive() is always return ture even though peer closed TLS and TCP connecton, I dont konwn how to detect whether TLS connection is alived.
The text was updated successfully, but these errors were encountered: