Skip to content

Instantly share code, notes, and snippets.

@termi
Created June 19, 2025 21:29
Show Gist options
  • Save termi/c5dfc799ff565e95349a35db9fccc747 to your computer and use it in GitHub Desktop.
Save termi/c5dfc799ff565e95349a35db9fccc747 to your computer and use it in GitHub Desktop.
MRE for "Aborting `signal` of server.lister method before actual listeting begin put a `listen` promise into a floating state"
// add into test/server.test.js
await t.test('listen should not start server if already aborted 2', async (t) => {
t.plan(2)
const controller = new AbortController()
controller.abort(new Error('aborting before actual start'))
const fastify = Fastify()
try {
// promise returning by fastify.listen is in "floating" state
await fastify.listen({ port: 1234, signal: controller.signal })
// unreachable code
} catch (e) {
// unreachable code
t.assert.strictEqual(e.message, 'aborting before actual start')
}
// unreachable code
t.assert.strictEqual(fastify.server.listening, false)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment