question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:12
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

10reactions
shrimpwagoncommented, Mar 1, 2022

Same issue. Rolling back to 13.0.2 worked

5reactions
gcandrade10commented, Feb 10, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: Can't set headers after they are sent to the client
The error "Error: Can't set headers after they are sent." means that you're already in the Body or Finished state, but some function...
Read more >
Understanding Node Error [ERR_HTTP_HEADERS_SENT]
This post describes why the Node Error [ERR_HTTP_HEADERS_SENT] cannot set headers after they are sent.
Read more >
code: 'err_http_headers_sent' - You.com | The AI Search ...
The 'errhttpheaders_sent' error code is a runtime error that occurs when Node.js attempts to set headers after they have already been sent to...
Read more >
Node.js HTTP: ERR_HTTP_HEADERS_SENT - Airbrake Blog
If you're receiving this error, this means that a part of your code is attempting to send a header after the body has...
Read more >
Cannot set headers after they are sent to the client in JS
The "Cannot set headers after they are sent to the client" error occurs when the server in an express.js application sends more than...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found