Skip to content
This repository has been archived by the owner on Feb 2, 2024. It is now read-only.

Response being written after being sent because res.sent is undefined #86

Closed
2 tasks done
jcbain opened this issue Apr 6, 2023 · 0 comments · Fixed by #88
Closed
2 tasks done

Response being written after being sent because res.sent is undefined #86

jcbain opened this issue Apr 6, 2023 · 0 comments · Fixed by #88

Comments

@jcbain
Copy link
Contributor

jcbain commented Apr 6, 2023

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

4.14.1

Plugin version

2.1.0

Node.js version

16.x

Operating system

Linux

Operating system version (i.e. 20.04, 11.3, 10)

NA

Description

When the request encounters and error and that error is passed to the callback it is possible to get into a scenario where the response attempts to write after it has already been sent because res.sent is undefined. This results in an uncaught exception [ERR_STREAM_WRITE_AFTER_END]: write after end to be thrown if a response has already been sent.

Looking at the type of res argument (http.ServerResponse) there isn't an attribute called sent so it seems like this we will always get into this conditional here .

Steps to Reproduce

Unsure of how to replicate this.

Expected Behavior

A check to see if all writeable data has been flushed in order to get into this conditional. Perhaps checking response.writeableFinished

jcbain added a commit to TugboatQA/fast-proxy that referenced this issue Apr 18, 2023
jcbain added a commit to TugboatQA/fast-proxy that referenced this issue Apr 18, 2023
mcollina pushed a commit that referenced this issue Jul 21, 2023
)

* fix: prevent response from being sent if all res headers have been flushed (#86)

* test: add test to assert that a response is not resent after res headers have been flushed (#86)

* fix: remove whitespace

* docs: add comment to err conditional in request callback

* fix: perform explicit check on response attributes

Co-authored-by: James Sansbury <[email protected]>

* fix linting errors

---------

Co-authored-by: James Sansbury <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant