Skip to content
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

api endpoint hangs and eventually times out when you res.status(204).send('anything') instead of throwing an error #28464

Closed
anguskeatinge opened this issue Aug 24, 2021 · 5 comments · Fixed by #28479
Assignees

Comments

@anguskeatinge
Copy link

What version of Next.js are you using?

11.1.0

What version of Node.js are you using?

14 (hosted on vercel)

What browser are you using?

chrome

What operating system are you using?

macOS

How are you deploying your application?

Vercel

Describe the Bug

res.status(204) // works as expected
res.status(200).send('message') // works as expected
res.status(204).send('something') // shits itself

The request hangs and eventually gives a timeout error.
It took me way longer to debug this than it should have. Completely my fault, I admit it.

This isn't an issue when running the app with yarn dev
It's only an issue for me when it is deployed on vercel.

reminder: http code 204 = no response

Expected Behavior

Some options:

  1. throw an error when attempting to send any data when the status is 204
  2. make the function typesafe so it can't call .send() if the status is a 204
  3. anything that would have made life a bit easier if there is a sneaky 204 in your code that is meant to be a 200.
  4. at the very least, having consistent behaviour between the dev environment and the deployed app would make this much faster to spot.

To Reproduce

res.status(204).send('message') when deployed on vercel

@anguskeatinge anguskeatinge added the bug Issue was opened via the bug report template. label Aug 24, 2021
@styfle styfle added kind: bug and removed bug Issue was opened via the bug report template. labels Aug 24, 2021
@styfle styfle self-assigned this Aug 24, 2021
@styfle
Copy link
Member

styfle commented Aug 24, 2021

This looks like a nasty bug, thanks!

May I ask, what is the use case for setting status code 204 (No Content) and then providing content anyway?

@anguskeatinge
Copy link
Author

Sorry if I wasn't clear, there is no use case.

It came about because I was refactoring some code and added some response data to an endpoint that had previously been a 204 and I didn't think to update the http status.

The bug is that it causes the lambda to hang until timeout without any error or warning in the code or in typescript.

@kodiakhq kodiakhq bot closed this as completed in #28479 Aug 25, 2021
kodiakhq bot pushed a commit that referenced this issue Aug 25, 2021
This ensures we handle 204 and 304 status codes correctly in API routes.  

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Errors have helpful link attached, see `contributing.md`

Fixes: #28464
@styfle
Copy link
Member

styfle commented Aug 25, 2021

This has been fixed in 11.1.1-canary.16.

You can try it out now with yarn add next@canary, thanks!

@anguskeatinge
Copy link
Author

Wow, you guys got on this fast. Solid.

Thanks @styfle 🚀

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 27, 2022
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.

3 participants