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

feat: add check for closed requests #162

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

zbrydon
Copy link

@zbrydon zbrydon commented May 6, 2024

Checklist

  • I have ensured my pull request is not behind the main or master branch of the original repository.
  • I have rebased all commits where necessary so that reviewing this pull request can be done without having to merge it first.
  • I have written a commit message that passes commitlint linting.
  • I have ensured that my code changes pass linting tests.
  • I have ensured that my code changes pass unit tests.
  • I have described my pull request and the reasons for code changes along with context if necessary.

Changes

Added a check for req.ctx.closed to ensure that, when a request is closed (canceled) before reaching the bodyparser middleware, the body of the closed request is not attempted to be parsed (which would result in an error). Instead, if the request is closed, then the middleware returns a 499 Client Closed Request status.

Reason

Errors can occur when parsing bodies of closed requests - stream not readable. This indicates the request was cancelled. This can happen when body parser is not on the "synchronous path" of a request - e.g. if Auth is verified asynchronously from headers before bothering to parse the bodies. This allows time for users to occasionally close the request, resulting in a 500 'stream not readable' error.

@zbrydon zbrydon changed the title Add check for closed requests feat: add check for closed requests May 6, 2024
@3imed-jaberi
Copy link
Member

@zbrydon Thanks for your contributions, could you please add test cases!

@zbrydon
Copy link
Author

zbrydon commented May 14, 2024

Thanks @3imed-jaberi, I have added a test 😄

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

Successfully merging this pull request may close these issues.

None yet

2 participants