nodejs / help

:sparkles: Need help with Node.js? File an Issue here. :rocket:
1.45k stars 278 forks source link

tcp server has been closed,but tcp port is still alive. #4260

Closed introspection3 closed 4 weeks ago

introspection3 commented 9 months ago

Version

v20.5.0

Platform

Linux hecs-87142 5.15.0-76-generic nodejs/node#83-Ubuntu SMP Thu Jun 15 19:16:32 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

No response

What steps will reproduce the bug?

cluster mode.

function freeTcpPortAsync() {
    let p = new Promise((resolve, reject) => {
        const server = net.createServer();
        server.unref();
        server.on('error', reject);
        server.on('connection', (socket) => {
            logger.warn('freeTcpPortAsync get a socket:' + socket.address().address)
            socket.end();
            socket.destroy();
        });
        server.listen(0, () => {
            const { port } = server.address();
            server.close(() => {
                resolve(port);
            });
        });
    });
    return p;
}

  let remotePort = await NetUtil.freeTcpPortAsync();
    await sleep(2000);
    logger.info('get a random remortPort:' + remotePort);

........................ then we use this port image

How often does it reproduce? Is there a required condition?

every often....

What is the expected behavior? Why is that the expected behavior?

No response

What do you see instead?

2023-10-05T18:15:15.207 INFO default 248728 :==>get a random remortPort:33007 2023-10-05T18:15:23.394 ERROR default 248723 :==>httpProxyError: connect ECONNREFUSED 127.0.0.1:33007

Additional information

No response

preveen-stack commented 9 months ago

In general, connection refused errors are generated during a connect system call when an application attempts to connect using TCP to a server port which is not open. https://www.pico.net/kb/what-is-a-tcp-connection-refused/

introspection3 commented 8 months ago

In general, connection refused errors are generated during a connect system call when an application attempts to connect using TCP to a server port which is not open. https://www.pico.net/kb/what-is-a-tcp-connection-refused/

it's node's bug

RedYetiDev commented 4 weeks ago

it's node's bug

TCP refusing a connection (as @preveen-stack mentioned) usually is caused by a setup error, and not Node.js.