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

Server Crashing with "Cannot set headers after they are sent to the client" #634

Open
Inrixia opened this issue Jun 7, 2020 · 11 comments
Open
Labels
good first issue Hacktoberfest Attract attention to this issue

Comments

@Inrixia
Copy link

Inrixia commented Jun 7, 2020

Steps to reproduce the issue, if applicable. Include the actual command and output and/or stack trace.

Not sure sorry as there is a lot of traffic on the server, just appears to all be normal GET requests.

What did you expect to happen?
The server to not crash. Ideally the error would be returned as a 503.

_http_outgoing.js:485
    throw new ERR_HTTP_HEADERS_SENT('set');
    ^

Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
    at ServerResponse.setHeader (_http_outgoing.js:485:11)
    at module.exports.ResponseStream.<computed> [as setHeader] (C:\Users\Administrator\AppData\Roaming\npm\node_modules\http-server\node_modules\union\lib\response-stream.js:100:34)
    at Object.exports.<computed> (C:\Users\Administrator\AppData\Roaming\npm\node_modules\http-server\node_modules\ecstatic\lib\ecstatic\status-handlers.js:57:7)
    at ReadStream.<anonymous> (C:\Users\Administrator\AppData\Roaming\npm\node_modules\http-server\node_modules\ecstatic\lib\ecstatic.js:298:24)
    at ReadStream.emit (events.js:223:5)
    at internal/fs/streams.js:167:12
    at FSReqCallback.wrapper [as oncomplete] (fs.js:470:5) {
  code: 'ERR_HTTP_HEADERS_SENT'
}

Tell us about your environment
Windows Server 2016
Node.js v12.14.1
Latest Version (Embedded/Global CLI Version from NPM)

Other information (related issues, suggestions for a fix, etc):
As far as I am aware the only thing that really needs to be done is catching the error and returning 503.

@Inrixia
Copy link
Author

Inrixia commented Jun 10, 2020

Currently I am just using a catch-all error handler and running off the source code rather than the global package. So just having a handler for that error would be a quick fix.

@thevictor13
Copy link

This only happens with known file extensions, in my case txt, json, etc. Not sure what headers are being sent early, but without looking at the source, I'm sure it's trying to set the mime-type header, which it fails to do.

@gcandrade10
Copy link

In my case it was happening for .json files, easy solution was to rollback to version 13.0.2

@shrimpwagon
Copy link

Same issue. Rolling back to 13.0.2 worked

@zbynek
Copy link
Contributor

zbynek commented Mar 4, 2022

This is kind of a duplicate of #756 , in both cases the headers error hides some problem deeper in the code. Proposed improvement in #791.

@shrimpwagon since you do not experience this with older versions of http-server, I think you might have the problem described in #756 and may be able to solve it by updating Node to 12.16 or later.

@thornjad maybe you can close this issue as duplicate, also please check the PR #791 if you have time.

flyskywhy added a commit to flyskywhy/PixelShapeRN that referenced this issue Apr 10, 2022
flyskywhy added a commit to flyskywhy/PixelShapeRN that referenced this issue Apr 26, 2022
flyskywhy added a commit to flyskywhy/g that referenced this issue May 4, 2022
@brizer
Copy link
Contributor

brizer commented May 9, 2022

Same issue. Rolling back to 13.0.2 worked

It works for me too. Thanks bro.

@jirikrepl
Copy link

I confirm, that the installation of v13 .. 13.1.0 works.
I tried to run this repository with http-server https://github.com/pixijs/examples
(as they recommend in readme)

@zbynek
Copy link
Contributor

zbynek commented Aug 17, 2022

@jirikrepl is it also OK if you keep the latest http-server and update node to the latest 12.X, 14.X or 16.X?

@jirikrepl
Copy link

@zbynek thanks! it was crashing for node 10, version http-server v14 works fine with node 16

@yutingkuang
Copy link

Same issue. Rolling back to 13.0.2 worked. Thanks!

@ccdaniele
Copy link

ccdaniele commented Oct 12, 2022

Working with 16 as well! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Hacktoberfest Attract attention to this issue
Projects
None yet
Development

No branches or pull requests

10 participants