parse-server: Can't set headers after they are sent.] Error: Can't set headers after they are sent. 2.2.18
Please read the following instructions carefully.
Check out https://github.com/ParsePlatform/parse-server/issues/1271 for an ideal bug report. The closer your issue report is to that one, the more likely we are to be able to help, and the more likely we will be to fix the issue quickly!
Many members of the community use Stack Overflow and Server Fault to ask questions. Read through the existing questions or ask your own!
- Stack Overflow: http://stackoverflow.com/questions/tagged/parse.com
- Server Fault: https://serverfault.com/tags/parse
For database migration help, please file a bug report at https://parse.com/help#report
Make sure these boxes are checked before submitting your issue – thanks for reporting issues back to Parse Server!
- [ x] You’ve met the prerequisites: https://github.com/ParsePlatform/parse-server/wiki/Parse-Server-Guide#prerequisites.
- [ x] You’re running the latest version of Parse Server: https://github.com/ParsePlatform/parse-server/releases
- [ x] You’ve searched through existing issues: https://github.com/ParsePlatform/Parse-Server/issues?utf8=✓&q=is%3Aissue Chances are that your issue has been reported or resolved before.
- [ x] You have filled out every section below. Issues without sufficient information are more likely to be closed.
Issue Description
While looking into a cloud code issue which I fixed, I saw this issue in my Heroku logs and Parse Dashboard logs… I have no idea what this could be but doesnt sound to good.
Not sure how to debug this, but needed to provide this to the community.
I should note rolling back to 2.2.17 this does not happen… 😕
2016-08-24T18:17:46.973Z - Uncaught internal server error. [Error: Can't set headers after they are sent.] Error: Can't set headers after they are sent.
at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:346:11)
at ServerResponse.header (/app/node_modules/express/lib/response.js:695:10)
at allowCrossDomain (/app/node_modules/parse-server/lib/middlewares.js:229:7)
at Layer.handle [as handle_request] (/app/node_modules/parse-server/node_modules/express/lib/router/layer.js:95:5)
at next (/app/node_modules/parse-server/node_modules/express/lib/router/route.js:131:13)
at Route.dispatch (/app/node_modules/parse-server/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/app/node_modules/parse-server/node_modules/express/lib/router/layer.js:95:5)
at /app/node_modules/parse-server/node_modules/express/lib/router/index.js:277:22
at param (/app/node_modules/parse-server/node_modules/express/lib/router/index.js:349:14)
at param (/app/node_modules/parse-server/node_modules/express/lib/router/index.js:365:14)
Environment Setup
- Server
- parse-server version (Be specific! Don’t say ‘latest’.) : 2.2.18
- Operating System: Heroku Dyno
- Hardware: Heroku Dyno
- Localhost or remote server? (AWS, Heroku, Azure, Digital Ocean, etc): Heroku Dyno
- Database
- MongoDB version: 3.2
- Storage engine: WiredTiger
- Hardware: M1 Cluster
- Localhost or remote server? (AWS, mLab, ObjectRocket, Digital Ocean, etc): Heroku
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 3
- Comments: 22 (9 by maintainers)
Hey guys,
I wanted to upgrade to 2.2.18 for the mongo connection improvements and ran into this issue as well.
After digging into it I found that it was because of #2338 (this commit). The change was added to allow “developers to add express handlers for successful completion of parse-server requests” however this causes problems for anyone who uses Parse Server in an existing Express app like this:
app.use('/parse', new ParseServer({...}));Why it is breaking is that by adding the
next()calls to the PromiseRouter the request gets passed down onto the nextapp.use(), which might try to handle it again causing the “Can’t set headers after they are sent” issue to arise.The correct workaround for doing this atm is to add a callback that stops the propagation:
I don’t think
next()should be called inside the PromiseRouter as the whole point of an Express middleware is that if it handles a request it stops the propagation of the request. I think to solve the needs put forward in #2338 there could be a callback in the ParseServer options for this (a request callback).👍
Same here. express 4.14.0
Waiting to hear on @blacha’s take on that as he provided that.
I think this happens when our client saves a userTag, stuff they tag in our app…
This happens on a few of our queries for POST from our app…