jeffbski / wait-on

wait-on is a cross-platform command line utility and Node.js API which will wait for files, ports, sockets, and http(s) resources to become available
MIT License
1.87k stars 77 forks source link

Unclosed connections #82

Open Bessonov opened 3 years ago

Bessonov commented 3 years ago

I use wait-on to wait for a server between restarts:

    await waitOn({
        resources: [`tcp:${publicIp}:22`],
        delay: 5000,
        timeout: 60000,
    })

After completion it seems like connections are not closed completely:

import wtf from 'wtfnode'
[...]
wtf.dump()

Outputs a long list:

[WTF Node?] open handles:
- File descriptors: (note: stdio always exists)
  - fd 2 (tty) (stdio)
  - fd 1 (tty) (stdio)
- Sockets:
  - 172.30.0.2:50814 -> undefined:undefined
    - Listeners:
      - connect: (anonymous) @ /home/workspace/infra/node_modules/.pnpm/wait-on@5.2.0/node_modules/wait-on/lib/wait-on.js:352
  - 172.30.0.2:50816 -> undefined:undefined
    - Listeners:
      - connect: (anonymous) @ /home/workspace/infra/node_modules/.pnpm/wait-on@5.2.0/node_modules/wait-on/lib/wait-on.js:352
[...]

Where the line 352 matches v5.2.0/lib/wait-on.js#L352. I've tried with destroy:

      .on('connect', () => {
        output(`  TCP connection successful to host:${host} port:${port}`);
        conn.end();
        conn.destroy();
        resolve(true);
      });

It helps (not tested with error/timeout), but I'm not sure that this is the way to go. May be it's something not well documented, because other people experience this too.