Skip to content

Conversation

@ddmoney420
Copy link

Summary

Fixes the timing of when res.complete is set to true on IncomingMessage to match Node.js behavior.

Fixes #26733

Problem

When using node:http for HTTP requests, the res.complete property was false inside the end event handler, even though the request completed successfully. This broke packages like @adyen/api-library which check:

res.on("end", () => {
    if (!res.complete) {
        reject(new Error("The connection was terminated while the message was still being sent"));
    }
});

Root Cause

  1. complete was only being set to true in _destroy, which happens AFTER the end event
  2. In Node.js, complete is set in parserOnMessageComplete BEFORE push(null) triggers end
  3. There was also a logic bug where complete = true was set before the !this.complete check

Solution

  1. Set this.complete = true in _read() BEFORE calling this.push(null)
  2. Fixed logic in _destroy() to check !this.complete before setting it to true

Test plan

  • Added regression test that verifies complete is true in end event
  • Verify @adyen/api-library works correctly

🤖 Generated with Claude Code

…6733)

This fixes an issue where the `complete` property on `IncomingMessageForClient`
was `false` inside the `end` event handler, even though the HTTP message had
been fully received. This broke packages like `@adyen/api-library` which check
`res.complete` in the `end` handler to verify message integrity.

The fix sets `complete = true` before calling `push(null)` in the `_read` method,
matching Node.js behavior where `complete` is set in `parserOnMessageComplete`
before signaling stream end.

Also fixed a logic bug in `_destroy` where `complete` was set to `true` before
checking if the message was incomplete, making the aborted check always false.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@CLAassistant
Copy link

CLAassistant commented Jan 29, 2026

CLA assistant check
All committers have signed the CLA.

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.

Node: HTTP request fails on res.complete

2 participants