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

Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client #4

Open
ghazel opened this issue Feb 19, 2019 · 4 comments

Comments

@ghazel
Copy link

ghazel commented Feb 19, 2019

Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
     at ServerResponse.setHeader (_http_outgoing.js:482:11)
     at vary (/myproj/node_modules/vary/index.js:147:9)
     at send (/myproj/node_modules/webp-middleware/index.js:24:3)
     at sendAndSave (/myproj/node_modules/webp-middleware/index.js:30:3)
     at /myproj/node_modules/webp-middleware/index.js:84:3
     at suppressedCallback (fs.js:205:5)
     at FSReqCallback.args [as oncomplete] (fs.js:146:20)

Looking at the headers around error time, Vary has already been set:

{
'x-powered-by': 'Express',
vary: 'Accept',
'accept-ranges': 'bytes',
'cache-control': 'public, max-age=0',
'last-modified': 'Tue, 05 Feb 2019 03:48:14 GMT',
etag: 'W/"1319a-168bbc5443a"',
'content-type': 'image/webp',
'content-length': 78234
}
@ghazel
Copy link
Author

ghazel commented Feb 19, 2019

This appears to happen after sendFile is attempted but fails: https://github.com/garthenweb/webp-middleware/blob/master/index.js#L73 and is retried, because Express sends the headers before the error occurs. (They specifically mention the caller should check res.headersSent: https://github.com/expressjs/express/blob/3d10279826f59bf68e28995ce423f7bc4d2f11cf/lib/response.js#L518 )

@garthenweb
Copy link
Owner

Thank you for the report and investigation. I will in the near future probably not have the time to fix this, but I would highly appreciate a PR!

@ghazel
Copy link
Author

ghazel commented Mar 11, 2019

The only solution I found was to disable the "try lookup cache for fast access" section entirely.

@garthenweb
Copy link
Owner

We might want to consider not to retry in case sent file failed... In the end, this will probably not solve your issue as it will fail anyhow.
Do you have an idea what can cause an error while sending the file? Are you able to provide a reproducible example?

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