Skip to content

fix: prevent ERR_HTTP_HEADERS_SENT when response headers sent during request wait - #166

Closed
vaibhavmashal wants to merge 1 commit into
pillarjs:masterfrom
vaibhavmashal:fix/headers-sent-during-request-wait
Closed

fix: prevent ERR_HTTP_HEADERS_SENT when response headers sent during request wait#166
vaibhavmashal wants to merge 1 commit into
pillarjs:masterfrom
vaibhavmashal:fix/headers-sent-during-request-wait

Conversation

@vaibhavmashal

Copy link
Copy Markdown

Closes #162

Description

When a request has an unread body, \ inalhandler\ registers an \onFinished(req, write)\ callback to defer sending the response until the request stream finishes. If another middleware or asynchronous operation sends response headers during this wait,
es.headersSent\ becomes \ rue. When \write()\ is subsequently executed, modifying headers or status code threw an \ERR_HTTP_HEADERS_SENT\ error.

This PR adds an early return check \if (res.headersSent) { return }\ inside \write()\ in \index.js\ and adds unit tests covering this scenario.

Copilot AI lite review requested due to automatic review settings September 8, 2026 16:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@krzysdz

krzysdz commented Sep 8, 2026

Copy link
Copy Markdown

Duplicate of #163

@krzysdz krzysdz marked this as a duplicate of #163 Sep 8, 2026
@krzysdz krzysdz closed this Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ERR_HTTP_HEADERS_SENT when headers are sent while finalhandler waits for the request to finish

3 participants