B
B
bro-dev2021-02-18 22:32:09
Computer networks
bro-dev, 2021-02-18 22:32:09

Why is tsp connecting slowly, where exactly is the limitation?

spoiler
const net = require('net');

const TCP_CONNECTION_TIMEOUT = 5555;

const checkTcp = (port, ip) => new Promise((resolve) => {
  const client = new net.Socket();
  client.setTimeout(TCP_CONNECTION_TIMEOUT);
  client.connect(port, ip, () => {
    resolve(true);
    client.destroy();
  });
  client.on('error', () => {
    resolve(false);
    client.destroy();
  });
});

console.time(1);
await Promise.all(proxies.map(({port, ip})=>checkTcp(port, ip) ))
console.timeEnd(1);


I check the proxy for just establishing a connection, 3k are checked for 2 minutes, why is it so slow, how to debug to understand where the bottleneck is.
Now there can be a node, a docker, a virtual machine, a host system with Windows, a router, a provider.
In theory, if I open everything at the same time, then the maximum time is their maximum timeout, which means 5 seconds.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bro-dev, 2021-02-19
@xPomaHx

setTimeout just doesn't work, it emits an event, and what to do with it you need to think for yourself,
I haven't read the doc https://nodejs.org/api/net.html#net_socket_settime...

spoiler
socket.setTimeout(3000);
socket.on('timeout', () => {
  console.log('socket timeout');
  socket.end();
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question