Psignal
Bun

property

http.IncomingMessage.signal

readonly signal: AbortSignal

An AbortSignal that is aborted when the underlying socket closes or the request is destroyed. The signal is created lazily on first access — no AbortController is allocated for requests that never use this property.

This is useful for cancelling downstream asynchronous work such as database queries or fetch calls when a client disconnects mid-request.

import http from 'node:http';

http.createServer(async (req, res) => {
  try {
    const data = await fetch('https://example.com/api', { signal: req.signal });
    res.end(JSON.stringify(await data.json()));
  } catch (err) {
    if (err.name === 'AbortError') return;
    res.statusCode = 500;
    res.end('Internal Server Error');
  }
}).listen(3000);