-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Description
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
deno/ext/node/polyfills/http.ts
Line 1949 in 6314c3c
| const options = normalized[0] as Partial<ListenOptions>; |
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.