cpprestsdk icon indicating copy to clipboard operation
cpprestsdk copied to clipboard

Reusing http_client instance with proxies

Open glukacsy opened this issue 10 years ago • 4 comments

Hi,

We ran into this weird issue that when we are trying to reuse an http_client instance with an http_config where proxy is set, the first time the request succeeds, but the subsequent times we get error 56, ""Failed to connect to any resolved proxy endpoint".

Tracked this down to http_client_asio.cpp and it almost looks like that the endpoints iterator is incremented the first time and then on subsequent requests points to the end?

Any thoughts?

Also, can you please confirm that in general it is OK (in fact desired) to reuse http_clients for the same base address and then bombard the same instance with ->request calls vs creating a new http_client per request?

regards, Gergely

glukacsy avatar Jun 02 '16 13:06 glukacsy

Yes, reusing http_client's is a best practice if you don't need to change any settings. Currently on Linux, we only pool connections within a single client (PR #156 might change this; it's still uncertain if we can make this work correctly w.r.t. the various settings) which has a significant performance impact.

Looking at http_client_asio.cpp, I don't quite see the issue. The endpoints iterator is incremented, but it's taken by value as a function parameter, so the increment should not affect any other state. Could you walk me through the issue with a bit more detail? Also, are you using HTTP or HTTPS?

ras0219-msft avatar Jun 06 '16 22:06 ras0219-msft

Thanks for confirming. So all I am doing is (on OS X) to go to System Prefrences/Network/Advanced/Proxies and then set up HTTPS proxy (so to answer your question: I am trying with HTTPS). Then I create an http_client instance, set the proxy on it and make a request, which succeeds - so proxy support is working great. Then I make another request to the same endpoint using the same http_client instance and I am getting error 56. Reproducible.

Regarding http_client_asio.cpp: you are most certainly right, I did not dig into the details, I just saw that that is the actual file where the error code is coming from. Probably I shouldn't have suggested that the issue is with the iterator.

Regards, Gergely PS: can you confirm what happens when we re-use the http client instance, but the HTTP connection times out? (e.g. I create instance, make a request, then don't make another request for a long time, but trying to use the same instance again)

glukacsy avatar Jun 07 '16 11:06 glukacsy

Re: PS Connection timeouts should be completely transparent; we should open up a new connection automatically and switch over. The timeout process is to remove the socket from the cache under a lock, so you should either successfully get the socket and it won't be timed out, or if it was timed out you won't find any sockets so a new one will open.

ras0219-msft avatar Jun 09 '16 00:06 ras0219-msft

Any more updates regarding this issue? It only happens on *NIX platforms it seems. We are experiencing the same issue on OS X/iOS and Linux.

leetal avatar Aug 14 '17 11:08 leetal