Skip to content

fix(node-fetch-server): fix logic for aborting requests#10726

Merged
mjackson merged 1 commit intoremix-run:mainfrom
MichaelDeBoey:fix-logic-for-aborting-requests
Sep 11, 2025
Merged

fix(node-fetch-server): fix logic for aborting requests#10726
mjackson merged 1 commit intoremix-run:mainfrom
MichaelDeBoey:fix-logic-for-aborting-requests

Conversation

@MichaelDeBoey
Copy link
Copy Markdown
Member

@MichaelDeBoey MichaelDeBoey force-pushed the fix-logic-for-aborting-requests branch from 47cf447 to 7b43c2d Compare August 27, 2025 16:46
// `finish` -> done rendering the response
// `close` -> response can no longer be written to
res.on('close', () => controller?.abort())
res.on('finish', () => (controller = null))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mjackson Here's a small repro of the issue we discovered in React Router that we fixed with this change. If we only use the close event to trigger aborting request signals, then we inadvertently also abort on successful/non-interrupted requests:

import * as http from 'node:http';
import { createRequestListener } from '@remix-run/node-fetch-server';

function handler(request) {
  // This should only fire if the request was interrupted
  request.signal.addEventListener('abort', () => console.log('request aborted'));
  return new Response('Hello, world!');
}

let server = http.createServer(createRequestListener(handler));

server.listen(3000);

Instead, we want to listen for a close event that was not preceded by a finish event. finish means we successfully finished sending response, so there is no longer any need to abort once we receive that.

@mjackson mjackson merged commit 8a23f5f into remix-run:main Sep 11, 2025
2 checks passed
@mjackson
Copy link
Copy Markdown
Member

Thanks, @MichaelDeBoey 🙏

mjackson added a commit that referenced this pull request Sep 11, 2025
@mjackson
Copy link
Copy Markdown
Member

Released in node-fetch-server v0.8.1

@MichaelDeBoey MichaelDeBoey deleted the fix-logic-for-aborting-requests branch September 12, 2025 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants