cpr icon indicating copy to clipboard operation
cpr copied to clipboard

error connection to proxy after a tot amount of multi threaded connection

Open bleriaf opened this issue 3 years ago • 3 comments

Description

I'm getting the error code " Failed to connect to port after ms: Address already in use " on all the requests after there are been done alot of requests (50k+) in a multi threaded application, what i do is create a cpr session then use .setProxies & .setProxyAuth then do the http request. what could i do to solve this issue? the code:

session.SetProxies( { { "https", "ip:port" } } );
session.SetProxyAuth( { { "https", cpr::EncodedAuthentication{ "user", "pw" } } } );

session.SetUrl("https://google.com/");
session.Get();

Expected Behavior

for it to not give any errors

Actual Behavior

gives error

Possible Fix

no idea

bleriaf avatar Sep 02 '22 22:09 bleriaf

The issue is, that you are probably using cpr on Windows, right? The error you get lets you know that you used up all free source ports on your system. This might be caused by not properly disposing cpr sessions after use.

To validate this, please try the following. What happens if you run out of ports, then you properly close your application and restart it. In theory Windows should free up all source ports from your application as soon as the process owning them exits.

COM8 avatar Sep 03 '22 12:09 COM8

correct i'm on windows, and yes after closing the process and then reopening it the issue is solved however i'm looking for a better solution. how would i be able to dispose cpr session after use like you mentioned?

bleriaf avatar Sep 03 '22 16:09 bleriaf

One option would be to reuse cpr::Session when ever possible. As soon as you call the destructor of cpr::Session resources should be freed automatically.

COM8 avatar Sep 07 '22 07:09 COM8