Skip to content

Http IncomingMessage.signal is always aborted for POST requests #63532

@ackava

Description

@ackava

Version

24.16

Platform

Linux

Subsystem

No response

What steps will reproduce the bug?

const http = require('node:http');

const server = http.createServer(async (req, res) => {
  // req.signal is an AbortSignal that aborts when the client disconnects
  const { signal } = req;

  console.log('Request received. Starting long task...');

  try {
    // You can pass the signal directly to other APIs like fetch() or fs.promises
    await performLongTask(signal);
    
    res.writeHead(200, { 'Content-Type': 'text/plain' });
    res.end('Task completed successfully!');
  } catch (err) {
    if (err.name === 'AbortError') {
      console.log('Request was aborted by the client. Cleaning up...');
    } else {
      console.error('An error occurred:', err);
      res.statusCode = 500;
      res.end('Internal Server Error');
    }
  }
});

// Mock function representing an asynchronous task
function performLongTask(signal) {
  return new Promise((resolve, reject) => {
    const timeout = setTimeout(() => {
      resolve();
    }, 5000);

    // Manually listen for the abort event if the API doesn't support signals
    signal.addEventListener('abort', () => {
      clearTimeout(timeout);
      reject(new DOMException('Aborted', 'AbortError'));
    }, { once: true });
  });
}

server.listen(3000, () => {
  console.log('Server running at http://localhost:3000/');
});

Sending get request works, but sending POST/PATCH with a request body always results in signal being aborted automatically at start of the requst.

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

Always

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

Signal should not aborted in any requests with body such as POST

What do you see instead?

For any request with body such as POST, signal is set to Aborted right from beginning.

Additional information

This was never an issue before 24.14

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions