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

Cannot properly handle POST requests with a body being aborted with AbortController #4690

Closed
2 tasks done
aniravi24 opened this issue Apr 21, 2023 · 2 comments
Closed
2 tasks done

Comments

@aniravi24
Copy link

aniravi24 commented Apr 21, 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.15.0

Plugin version

No response

Node.js version

18.15.0

Operating system

Linux

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

ArchLinux latest

Description

I was following this guide to listen to aborted requests on a particular route (it's important to me that I can do it on a particular route - I don't want the hook variant).

https://www.fastify.io/docs/latest/Guides/Detecting-When-Clients-Abort/

When doing a POST request with a body, the close event gets called as soon as the incoming request is made.

It works fine on GET requests, and POST requests without a body.

Steps to Reproduce

https://www.fastify.io/docs/latest/Guides/Detecting-When-Clients-Abort/

Follow this exact guide, but replace app.get with app.post and update the fetch call to call with a POST, and include a non-empty body. For example.

fetch("http://localhost:3000", {
      body: "some random text",
      method: "POST",
      signal
    })

Since Node 18 comes with fetch and other APIs built-in, no additional packages or polyfills needed.

Expected Behavior

When doing a POST request, even if it contains a body, I want the event to fire normally.

@climba03003
Copy link
Member

climba03003 commented Apr 21, 2023

Personally, I don't like to have this guide as it never been a reliable way to detect what you needs.
It is something that should be ask in node/help or node/discussion instead of here.

Anyway, the problem is that when the body is consumed. No extra close event would fired.
You should check the property yourself instead of relying the close event.

See fastify/help#866

If you would like a reliable way, look forward to node changes.
See nodejs/node#40775 nodejs/node#41117

@aniravi24
Copy link
Author

Got it, thank you! @climba03003

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

No branches or pull requests

2 participants