node-libcurl icon indicating copy to clipboard operation
node-libcurl copied to clipboard

Proxy Doesn't Change

Open mehmetuken opened this issue 1 year ago • 17 comments

Hi, No matter how many request.session objects I create in the same Node.js process, it always uses the initially assigned proxy and ignores other proxies. Even if I pass a new proxy as a parameter when doing session.get, it still uses the first proxy.

const proxies = [
    {
        proxy: 'http://localhost:3000',
        username: 'user1',
        password: 'password1',
    },
    {
        proxy: 'http://localhost:3001',
        username: 'user2',
        password: 'password2',
    },
    {
        proxy: 'http://localhost:3002',
        username: 'user3',
        password: 'password3',
    },
];


for (const proxy of proxies) {
    const session = requests.session({
        proxy: proxy,
    });

    const response = session.get('https://ipinfo.io/json');
    console.log(response.json);

    const response2 = session.get('https://ipinfo.io/json', {
        proxy: proxies[1],
    });
    console.log(response2.json);

}
// Output:
// ip from proxy 0
// ip from proxy 0

// ip from proxy 0
// ip from proxy 0

// ip from proxy 0
// ip from proxy 0

mehmetuken avatar Oct 19 '24 05:10 mehmetuken

Looks like a socket connect reuse problem ...

Ossianaa avatar Oct 19 '24 06:10 Ossianaa

This issue is resolved, but in cases like Promise.all, it still uses the first assigned proxy.

const proxies = [
    {
        proxy: 'http://localhost:3000',
        username: 'user1',
        password: 'password1',
    },
    {
        proxy: 'http://localhost:3001',
        username: 'user2',
        password: 'password2',
    },
    {
        proxy: 'http://localhost:3002',
        username: 'user3',
        password: 'password3',
    },
];


async function sendRequest(proxy) {
    const session = requests.session({
        proxy: proxy,
    });

    const response = session.get('https://ipinfo.io/json');
    console.log(response.json);

    const response2 = session.get('https://ipinfo.io/json', {
        proxy: proxies[1],
    });
    console.log(response2.json);
}

const promises = proxies.map(proxy => sendRequest(proxy));
await Promise.all(promises);

mehmetuken avatar Oct 19 '24 06:10 mehmetuken

This issue is resolved, but in cases like Promise.all, it still uses the first assigned proxy.

give me a code

Ossianaa avatar Oct 19 '24 06:10 Ossianaa

This issue is resolved, but in cases like Promise.all, it still uses the first assigned proxy.

give me a code

I edited and added the comment above.

mehmetuken avatar Oct 19 '24 06:10 mehmetuken

This issue is resolved, but in cases like Promise.all, it still uses the first assigned proxy.

give me a code

I edited and added the comment above.

look like CURLOPT_PIPEWAIT cause problem

Ossianaa avatar Oct 19 '24 06:10 Ossianaa

It's solved. Thank you so much!

mehmetuken avatar Oct 19 '24 07:10 mehmetuken

So, it is now impossible to reuse TCP connections, right? I experienced similar issue with proxies and was needed to set up connectReuse: false to solve it.

iamoskvin avatar Oct 21 '24 09:10 iamoskvin

So, it is now impossible to reuse TCP connections, right? I experienced similar issue with proxies and was needed to set up connectReuse: false to solve it.

yes, If it is reuse connect, it may increase performance but it will do the wrong thing

Ossianaa avatar Oct 21 '24 09:10 Ossianaa

So, it is now impossible to reuse TCP connections, right? I experienced similar issue with proxies and was needed to set up connectReuse: false to solve it.

yes, If it is reuse connect, it may increase performance but it will do the wrong thing

Thanks. Is it possible to make curl reuse connects but with proper proxy handling? We need to take into account not only proxy host/port but also login and password (because proxy server can switch an external IP based on login/pwd). The curl does not do this by default, as far as I understand: it reuses a connection if it has the same host and password.

iamoskvin avatar Oct 21 '24 09:10 iamoskvin

So, it is now impossible to reuse TCP connections, right? I experienced similar issue with proxies and was needed to set up connectReuse: false to solve it.

yes, If it is reuse connect, it may increase performance but it will do the wrong thing

Thanks. Is it possible to make curl reuse connects but with proper proxy handling? We need to take into account not only proxy host/port but also login and password (because proxy server can switch an external IP based on login/pwd). The curl does not do this by default, as far as I understand: it reuses a connection if it has the same host and password.

I will see if there is a better way, and if you have a solution, pr please :)

Ossianaa avatar Oct 21 '24 09:10 Ossianaa

So, it is now impossible to reuse TCP connections, right? I experienced similar issue with proxies and was needed to set up connectReuse: false to solve it.

yes, If it is reuse connect, it may increase performance but it will do the wrong thing

Thanks. Is it possible to make curl reuse connects but with proper proxy handling? We need to take into account not only proxy host/port but also login and password (because proxy server can switch an external IP based on login/pwd). The curl does not do this by default, as far as I understand: it reuses a connection if it has the same host and password.

I will see if there is a better way, and if you have a solution, pr please :)

Thanks. I don't have a better solution currently.

iamoskvin avatar Oct 21 '24 09:10 iamoskvin

So, it is now impossible to reuse TCP connections, right? I experienced similar issue with proxies and was needed to set up connectReuse: false to solve it.

yes, If it is reuse connect, it may increase performance but it will do the wrong thing

Thanks. Is it possible to make curl reuse connects but with proper proxy handling? We need to take into account not only proxy host/port but also login and password (because proxy server can switch an external IP based on login/pwd). The curl does not do this by default, as far as I understand: it reuses a connection if it has the same host and password.

I will see if there is a better way, and if you have a solution, pr please :)

Thanks. I don't have a better solution currently.

If it was the username and password that caused the proxy reuse. I should be able to easily fix it and turn connectReuse back on

Ossianaa avatar Oct 21 '24 09:10 Ossianaa

So, it is now impossible to reuse TCP connections, right? I experienced similar issue with proxies and was needed to set up connectReuse: false to solve it.

yes, If it is reuse connect, it may increase performance but it will do the wrong thing

Thanks. Is it possible to make curl reuse connects but with proper proxy handling? We need to take into account not only proxy host/port but also login and password (because proxy server can switch an external IP based on login/pwd). The curl does not do this by default, as far as I understand: it reuses a connection if it has the same host and password.

I will see if there is a better way, and if you have a solution, pr please :)

Thanks. I don't have a better solution currently.

If it was the username and password that caused the proxy reuse. I should be able to easily fix it and turn connectReuse back on

In the error I encountered, there were the same IP:PORT with different username and password combinations.

mehmetuken avatar Oct 21 '24 09:10 mehmetuken

So, it is now impossible to reuse TCP connections, right? I experienced similar issue with proxies and was needed to set up connectReuse: false to solve it.

yes, If it is reuse connect, it may increase performance but it will do the wrong thing

Thanks. Is it possible to make curl reuse connects but with proper proxy handling? We need to take into account not only proxy host/port but also login and password (because proxy server can switch an external IP based on login/pwd). The curl does not do this by default, as far as I understand: it reuses a connection if it has the same host and password.

I will see if there is a better way, and if you have a solution, pr please :)

Thanks. I don't have a better solution currently.

If it was the username and password that caused the proxy reuse. I should be able to easily fix it and turn connectReuse back on

In the error I encountered, there were the same IP:PORT with different username and password combinations.

But I see in your code that you used different proxy ports: 3000, 3001, 3002.

iamoskvin avatar Oct 21 '24 09:10 iamoskvin

So, it is now impossible to reuse TCP connections, right? I experienced similar issue with proxies and was needed to set up connectReuse: false to solve it.

yes, If it is reuse connect, it may increase performance but it will do the wrong thing

Thanks. Is it possible to make curl reuse connects but with proper proxy handling? We need to take into account not only proxy host/port but also login and password (because proxy server can switch an external IP based on login/pwd). The curl does not do this by default, as far as I understand: it reuses a connection if it has the same host and password.

I will see if there is a better way, and if you have a solution, pr please :)

Thanks. I don't have a better solution currently.

If it was the username and password that caused the proxy reuse. I should be able to easily fix it and turn connectReuse back on

You disabled CURLPIPE_MULTIPLEX to prevent issues with proxies. Do I understand correctly that the issues occur only in the case of proxies with user/password. If I use passwordless proxies with different hosts/ports, then it looks like there is no issue with connection reuse, right? Is connection pool bound to curllib instance of is common for all instances? Thank you.

iamoskvin avatar Oct 25 '24 11:10 iamoskvin

So, it is now impossible to reuse TCP connections, right? I experienced similar issue with proxies and was needed to set up connectReuse: false to solve it.

yes, If it is reuse connect, it may increase performance but it will do the wrong thing

Thanks. Is it possible to make curl reuse connects but with proper proxy handling? We need to take into account not only proxy host/port but also login and password (because proxy server can switch an external IP based on login/pwd). The curl does not do this by default, as far as I understand: it reuses a connection if it has the same host and password.

I will see if there is a better way, and if you have a solution, pr please :)

Thanks. I don't have a better solution currently.

If it was the username and password that caused the proxy reuse. I should be able to easily fix it and turn connectReuse back on

You disabled CURLPIPE_MULTIPLEX to prevent issues with proxies. Do I understand correctly that the issues occur only in the case of proxies with user/password. If I use passwordless proxies with different hosts/ports, then it looks like there is no issue with connection reuse, right? Is connection pool bound to curllib instance of is common for all instances? Thank you.

it looks like there is no issue with connection reuse, right? I did not test the proxy for all cases, but disabling it CURLPIPE_MULTIPLEX that the proxy is not reused under http2

Is connection pool bound to curllib instance of is common for all instances? yes, all instance are bound pool

https://github.com/Ossianaa/node-libcurl/blob/95afc7655bdfd5540fd6e04e8ef20eccbe2bd8bf/src/libcurl/bao_curl_node_addon.cpp#L708

Ossianaa avatar Oct 25 '24 11:10 Ossianaa

So, it is now impossible to reuse TCP connections, right? I experienced similar issue with proxies and was needed to set up connectReuse: false to solve it.

yes, If it is reuse connect, it may increase performance but it will do the wrong thing

Thanks. Is it possible to make curl reuse connects but with proper proxy handling? We need to take into account not only proxy host/port but also login and password (because proxy server can switch an external IP based on login/pwd). The curl does not do this by default, as far as I understand: it reuses a connection if it has the same host and password.

I will see if there is a better way, and if you have a solution, pr please :)

Thanks. I don't have a better solution currently.

If it was the username and password that caused the proxy reuse. I should be able to easily fix it and turn connectReuse back on

You disabled CURLPIPE_MULTIPLEX to prevent issues with proxies. Do I understand correctly that the issues occur only in the case of proxies with user/password. If I use passwordless proxies with different hosts/ports, then it looks like there is no issue with connection reuse, right? Is connection pool bound to curllib instance of is common for all instances? Thank you.

it looks like there is no issue with connection reuse, right? I did not test the proxy for all cases, but disabling it CURLPIPE_MULTIPLEX that the proxy is not reused under http2

Is connection pool bound to curllib instance of is common for all instances? yes, all instance are bound pool

https://github.com/Ossianaa/node-libcurl/blob/95afc7655bdfd5540fd6e04e8ef20eccbe2bd8bf/src/libcurl/bao_curl_node_addon.cpp#L708

There may be a better solution but I've disabled all the relevant ones for now

Ossianaa avatar Oct 25 '24 11:10 Ossianaa

work in v1.7.8

Ossianaa avatar May 31 '25 20:05 Ossianaa