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

(Fix) Stopped additional responses from being sent if a limit handler exists #264

Merged
merged 1 commit into from
Jan 11, 2021

Conversation

Benez11
Copy link
Contributor

@Benez11 Benez11 commented Jan 8, 2021

  • The method "closeConnection" attempts to send a second response despite the parsed "limitHandler" function initially executing and sending its own custom response.
  • This leads to the error - "Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client".
  • I have placed a condition for the "closeConnection" method to only be executed if a valid "limitHandler" function is NOT parsed into the options argument.

…xists.

- The method "closeConnection" attempts to send a second response despite the parsed "limitHandler" function initially executing and sending its own custom response.
- This leads to the error - "Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client".
- I have placed a condition for the "closeConnection" method to only be executed if a valid "limitHandler" function is NOT parsed into the options argument.
@richardgirges
Copy link
Owner

Thank you! I will get this pushed up on the next release shortly.

@richardgirges richardgirges merged commit 8cd0c21 into richardgirges:master Jan 11, 2021
@mayurpunjabi
Copy link

mayurpunjabi commented Jun 3, 2021

I updated to latest version 1.2.1, but I am still getting "Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client" after assigning limitHandler. Can someone help?

app.use(fileUpload({ limits: { fileSize: 3 * 1024 * 1024 }, limitHandler: (req, res, next) => res.json({ 'success': false, 'message': 'File size limit has been reached' }) }));

@therealsujitk
Copy link

therealsujitk commented Dec 3, 2022

I'm getting this issue too, looks like the next() function is still being called after an abort. @richardgirges is there a fix for this? for now I've fixed this with in my function.

if (res.headersSent) {
  return;
}

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.

4 participants