socks5-https-client icon indicating copy to clipboard operation
socks5-https-client copied to clipboard

Concurrent requests

Open wahid opened this issue 7 years ago • 2 comments

When doing concurrent requests the first proxy used can never be changed.

        var myip = "https://api.ipify.org?format=json";

        var res = await request({ 
            method: 'GET',
            uri: myip,
            agentClass: Agent,
            agentOptions: {
                socksHost: proxy.split(":")[0],
                socksPort: proxy.split(":")[1]
            },
            rejectUnauthorized: false
        });

This is giving me the same ip for every request while i change the proxy on every request.

179.209.175.59:28061 {"ip":"179.209.175.59"} 189.122.40.220:58577 {"ip":"179.209.175.59"} 189.6.142.94:16943 {"ip":"179.209.175.59"} 187.39.53.6:65000 {"ip":"179.209.175.59"} 177.142.117.96:46489

wahid avatar Dec 04 '17 13:12 wahid

@wahid I had the same issue, maybe others will come to this page looking for a solution. In my case the issue was not related to this package, I had to add maxSockets option on request module:

var myip = 'https://api.ipify.org?format=json';

var res = await request({
	method: 'GET',
	uri: myip,
	agentClass: Agent,
	agentOptions: {
		socksHost: proxy.split(':')[0],
		socksPort: proxy.split(':')[1]
	},
        pool: {maxSockets: Infinity}, // <=======
	rejectUnauthorized: false
});

From Documentation

  • pool - an object describing which agents to use for the request. If this option is omitted the request will use the global agent (as long as your options allow for it). Otherwise, request will search the pool for your custom agent. If no custom agent is found, a new agent will be created and added to the pool. Note: pool is used only when the agent option is not specified.
    • A maxSockets property can also be provided on the pool object to set the max number of sockets for all agents created (ex: pool: {maxSockets: Infinity}).
    • Note that if you are sending multiple requests in a loop and creating multiple new pool objects, maxSockets will not work as intended. To work around this, either use request.defaults with your pool options or create the pool object with the maxSockets property outside of the loop.

Erfaanism avatar Apr 23 '18 09:04 Erfaanism

I have the same problem, the second request will use the proxy set by the first request.

shellus avatar Aug 30 '18 01:08 shellus