Skip to content

server.listen({ signal }) option ignored in Node.js polyfill #30508

@vadimpiven

Description

@vadimpiven

Summary

The signal option in server.listen() is not respected in Deno's Node.js polyfill. When an AbortController signal is aborted, the server continues running instead of closing automatically as it does in Node.js.

Expected behavior:
When server.listen({ signal: abortController.signal }) is called and the signal is later aborted, the server should close automatically, matching Node.js behavior described in Node documentation.

Actual behavior:
The server ignores the aborted signal and continues running. This happens because signal field of options parsed in

const options = normalized[0] as Partial<ListenOptions>;
is never read. Deno documentation does not list signal as a supported option, but does say interface ListenOptions extends Abortable (with broken link to Abortable by the way), which to me implies that signal option should be supported. There are multiple TODO's mentioning @bnoordhuis around the code, may be you can suggest a quick fix for that?)

Reproduction

import { createServer } from 'node:http';

const abortController = new AbortController();

createServer((_req, res) => {
  res.writeHead(404).end();
}).on('listening', () => {
  abortController.abort();
  setTimeout(() => process.exit(1), 1000);
}).on('close', () => {
  process.exit(0);
}).listen({
  host: 'localhost',
  port: 0,
  signal: abortController.signal
});

Test results:

  • Node.js: Exits with code 0 (server closes when signal aborted)
  • Deno: Exits with code 1 (server ignores signal)

Environment

  • Deno version: 2.4.5
  • OS: macOS

Workaround

Manually call server.close() when the signal is aborted instead of relying on the signal option.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working correctlynode compat

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions