Ghost: [Docker] Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
Welcome 👋
Please keep in mind that GitHub is our office. We invite you to share any bug reports here 🐛…
For anything else please use https://forum.ghost.org 👫
Issue Summary
Sometimes, my docker install of Ghost crashes and restarts the container. The docker logs show this error:
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
Followed by this output:
at ServerResponse.setHeader (_http_outgoing.js:561:11)
at ServerResponse.header (/var/lib/ghost/versions/4.11.0/node_modules/express/lib/response.js:771:10)
at ServerResponse.send (/var/lib/ghost/versions/4.11.0/node_modules/express/lib/response.js:170:12)
at /var/lib/ghost/versions/4.11.0/core/server/web/shared/middlewares/error-handler.js:200:32
at /var/lib/ghost/versions/4.11.0/node_modules/express-hbs/lib/hbs.js:635:23
at /var/lib/ghost/versions/4.11.0/node_modules/express-hbs/lib/resolver.js:29:5
at tryCatcher (/var/lib/ghost/versions/4.11.0/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/var/lib/ghost/versions/4.11.0/node_modules/bluebird/js/release/promise.js:547:31)
at Promise._settlePromise (/var/lib/ghost/versions/4.11.0/node_modules/bluebird/js/release/promise.js:604:18)
at Promise._settlePromise0 (/var/lib/ghost/versions/4.11.0/node_modules/bluebird/js/release/promise.js:649:10)
at Promise._settlePromises (/var/lib/ghost/versions/4.11.0/node_modules/bluebird/js/release/promise.js:725:18)
at _drainQueueStep (/var/lib/ghost/versions/4.11.0/node_modules/bluebird/js/release/async.js:93:12)
at _drainQueue (/var/lib/ghost/versions/4.11.0/node_modules/bluebird/js/release/async.js:86:9)
at Async._drainQueues (/var/lib/ghost/versions/4.11.0/node_modules/bluebird/js/release/async.js:102:5)
at Immediate.Async.drainQueues [as _onImmediate] (/var/lib/ghost/versions/4.11.0/node_modules/bluebird/js/release/async.js:15:14)
at processImmediate (internal/timers.js:464:21)
After that, the service is restarted and it functions fine again.
To Reproduce
- Setup Ghost using official Docker image
- Run it with docker-compose that restarts the container on failure.
- At some point the user gets a half loading page on the first visit. Refreshing with F5 gives a 404 error.
- After a few minutes you can press F5 again and Ghost will be back up and running.
Technical details:
- Ghost Version: 4.11.0 (docker)
- Node Version: What is in the 4.11.0 docker container
- Browser/OS: Server runs Manjaro ARM with Docker. Client runs Manjaro x64 using Firefox.
- Database: What is in the 4.11.0 docker container.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 16 (2 by maintainers)
I have EXACTLY the same issue. Haven’t found any solutions to it yet. Probably will switch away from Ghost soon too because of this. Would be better to find a solution though.
Posted about it on the Ghost Forums too, but got 0 replies: https://forum.ghost.org/t/cannot-set-headers-site-only-loads-properly-on-third-refresh/25011
I just today updated my containers to
4.154.164.174.18 and can confirm that the big still exists, with the same error log as in the initial issue. Upon loading the home page, the images fail to load, and after hitting „reload“, the „site is under maintenance“ message appears.I have noticed however that it seems to happen more often in the official Casper theme than in other themes, this could be a coincidence though.Edit: This was a coincidence. I’ve switched to the Alto theme and the issue persists. It probably only happened on that site because it has more traffic. I’ll probably just switch away from using Ghost.Also, here is the current log
Interestingly, it does not crash the container every time, but about every third to fourth time… Which still is multiple times a day.
~On my servers, while this bug still persists after the latest update for the container (4.15), it doesn’t lead to the container crashing anymore. Only the log message is still there.~
Sadly this is not true anymore, I just had a lucky streak. Version 4.15 and 4.16 in Docker still display this bug.
The error is in my log
docker log <container-id>.I haven’t had it happen in a while though (now running 4.16). When it does happen, the main page will not be loading any pictures properly. And hitting F5 just after that, results in a Bad Gateway error, because the container is rebooting. When the container is done rebooting, everything works fine.