fix(node): call request abort controller only on close#161
Conversation
📝 WalkthroughWalkthroughThe PR fixes a bug where Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~15 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
commit: |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@test/_fixture.ts`:
- Around line 207-218: The test route handling "/body-cancel" currently
hardcodes abortedAfterCancel to false; change it to read the real abort signal
state by assigning abortedAfterCancel = req.signal.aborted (or evaluating
req.signal.aborted immediately after await reader.cancel()) so the handler
returns the actual signal state; update the variable in the block that declares
abortedAfterCancel and ensure the subsequent abortedAfterTimeout still reads
req.signal.aborted after the timeout.
🧹 Nitpick comments (1)
test/_tests.ts (1)
161-179: Make the request body stream finite to avoid flaky hangs.
The stream never closes, which can keep the request body open and cause nondeterministic behavior in fetch/undici. Consider closing after the first chunk.♻️ Proposed change
- body: new ReadableStream({ - async pull(controller) { - await new Promise((resolve) => setTimeout(resolve, 100)); - controller.enqueue(new TextEncoder().encode("hello")); - }, - }), + body: new ReadableStream({ + async start(controller) { + await new Promise((resolve) => setTimeout(resolve, 100)); + controller.enqueue(new TextEncoder().encode("hello")); + controller.close(); + }, + }),
resolves #160
req.bodyinitiates Node Readable.toWeb. When the read is canceled, it emits anerrorevent on the original request for "Operation canceled," which can be wrongly interpreted as if the original client is disconnected and triggers the req abort controller.This PR removes the additional
errorevent listener from the node event and relies on the res close event to trigger the abort controller.This makes behavior consistent with Bun and Deno.
Summary by CodeRabbit
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.