eidheim / Simple-Web-Server

A very simple, fast, multithreaded, platform independent HTTP and HTTPS server and client library implemented using C++11 and Boost.Asio. Created to be an easy way to make REST resources available from C++ applications.
MIT License
2.62k stars 755 forks source link

Http/Https Client needs time to live parameter for free connection in pool #142

Closed AlexanderKotliar closed 7 years ago

AlexanderKotliar commented 7 years ago

If there is a sighnificant amount of time between successive requests to one host (~ 60 seconds and more), free connection in pool is timed out on server side, but client use it for next request. It needs to drop such connection after config.time_to_live.

eidheim commented 7 years ago

At the next request, after the server disconnects, the client will reconnect the connection. See https://github.com/eidheim/Simple-Web-Server/blob/master/client_http.hpp#L489.

eidheim commented 7 years ago

I have to add that the client reconnect feature was added a month or so ago. Do you have this issue with latest master?

AlexanderKotliar commented 7 years ago

I was wrong with my suggestion, indeed, the socket is reopened. The problem is with https client: if the full setup (create_connection()) is not invoked just socket reopened, then handshake fails with error code 2.

AlexanderKotliar commented 7 years ago

The way to reproduce: connect to https server (I load curl's ca-bundle.crt). Wait about 60 seconds and connect again.

eidheim commented 7 years ago

Thank you, I managed to reproduce this on Linux. I could not create a decent fix for the master branch, due to the static functions that are used there, but this issue should be fixed on the v3 branch. I'll probably merge this branch in a week or so though, but feel free to try it out.