-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: add a check if the res is destroyed before sending response #10106
fix: add a check if the res is destroyed before sending response #10106
Conversation
In the case of using `curl` or a similar tool on the command line, or if the client decides to end the request for a streamed file early without the check we would end up causing a server crash. Now, we will just not send the response as the client has already decided how to move on. fix: nestjs#10105
I had to use node's `http` module for this because I could not get `supertest`s `abort` method to work properly. With the raw `http` module I was able to use `req.destroy()` to cancel the request early. We now see the error from a premature closure, but are still able to make extra requests afterwards
Pull Request Test Coverage Report for Build 6bd812e5-d78a-48a1-b3ea-7496b7f1d761
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some suggestions, awesome work Jay!
As we make use of the `http` module instead of axios or supertest we have tomake use of some rather low level code. Using this utils file we can have clearer names of what is happening in each request to make it easier to follow what's happening. I've also added in some comments about why each part is the way it is for clarity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, nice explanation of the details Jay, this is awesome :)
LGTM |
Hi, I am on NestJs cli v9.0.0.. I am getting this issue while streaming video files. Any solutions to fix this issue.. |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
If a client currently closes the request before the stream finishes we get an error about not being able to send headers to a response that is already sent. It should be noted that this is express only, fastify does not have this issue
Issue Number: #10105
What is the new behavior?
In the case of using
curl
or a similar tool on the command line,or if the client decides to end the request for a streamed file early
without the check we would end up causing a server crash. Now, we will
just not send the response as the client has already decided how to
move on.
Does this PR introduce a breaking change?
Technically yes due to the fact that the server now no longer dies, but that is the expected case, so I believe this should be fine as a
patch
rather than amajor
bump. The fact that we actually now prevent a crash is the good thing 🐱Other information