nodejs / node

Node.js JavaScript runtime ✨🐢🚀✨
https://nodejs.org
Other
107.37k stars 29.49k forks source link

http2.Http2Server listen conditionally leaves an open file handle after cleanup #47006

Open jason-gigastar opened 1 year ago

jason-gigastar commented 1 year ago

Version

18.14.0

Platform

Linux 5.14.0-1045-oem #51-Ubuntu SMP Mon Jul 4 06:41:22 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

node:http2

What steps will reproduce the bug?

Given the following Jest test suite, replace test with test.only and run each scenario in isolation.

import http2 from 'node:http2';

function verifyListen(host: string | undefined): void {
    const server = http2.createServer({});
    server.listen(8888, host);
    server.close();
}

describe.only('HttpServer', () => {
    test('good scenario', () => {
        console.log('good scenario');
        verifyListen(undefined);
    });

    test('bad scenario 1', () => {
        console.log('bad scenario 1');
        verifyListen('localhost');
    });

    test('bad scenario 2', () => {
        console.log('bad scenario 2');
        verifyListen('127.0.0.1');
    });
});

Jest command: npx jest --testRegex test/BugReport.ts --detectOpenHandles

There are no connections being created, just listen on the port and then close the port.

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

Always when localhost or 127.0.0.1 are used.

What is the expected behavior?

When close is called there should be no open handles after all connections complete. In the simplest case there are no connections needed to cleanup and still there's an open handle.

What do you see instead?

The good scenario runs without problems.

The 2 bad scenarios, when run in isolation, both yield:

Jest has detected the following 1 open handle potentially keeping Jest from exiting:

  ●  TCPSERVERWRAP

      3 | function verifyListen(host: string | undefined): void {
      4 |     const server = http2.createServer({});
    > 5 |     server.listen(8888, host);
        |            ^
      6 |     server.close();
      7 | }
      8 |

Additional information

No response

ywave620 commented 1 year ago

Could you tell what the jest version is in use?

jason-gigastar commented 1 year ago

Jest 29.5.0