test_runner: global after not run if handles are open

Version

v20.5.0

Platform

mac

Subsystem

test_runner

What steps will reproduce the bug?

Considder the following test:

const { before, after, test } = require('node:test')
const { createServer } = require('http')

let server

before(async () => {
  console.log('before');
  server = createServer((req, res) => {
    res.end('hello')
  })

  await new Promise((resolve, reject) => {
    server.listen(0, (err) => {
      if (err) reject(err)
      else resolve()
    })
  })
})

after(() => {
  console.log('after');
  server.close()
})

test('something', () => {
  console.log('test');
})

We are trying to dispose of a server (or a connection to a DB) inside a global after but the global after is never run.

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

all the times

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

for the test to pass / the after hook to be executed

What do you see instead?

the after hook is not executed and therefore the test never terminates

Additional information

No response