-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Http Headers related error with code pulled. #2362
Comments
I'm noticing this, too. I had done a pull on master branch on 7/12. That had been working fine. When I pulled yesterday and deployed the newer parse server code, I started seeing this error. I suspect it must have been a commit that was introduced between 7/12 and 7/21. @flovilmart Have you noticed this error, too? |
I haven't noticed it, not sure what would generate it. |
It doesn't seem to happen when using parse-server from the CLI, how did you configure/run it? We recently added next handlers (#2338) this is maybe because your setup has a middleware that write the headers after they are written from parse-server |
Thank you for the reply Florent. We are running it on AWS Elastic Beanstalk on a t2.medium and seeing this error in the nodejs logs. The configuration of our environment has not changed over the last 3 weeks and we are running it with verbose set to true. The only thing we changed was we pulled the lasted parse-server code from master. The error seems to happen any time a cloud code method is invoked. We use promises in our methods. It definitely seems to have been caused by the changes you pointed me to in PromiseRouter.js. Once I removed those changes in my local branch and redeployed, the errors went away. What is the purpose of those changes? Is that something that can be reverted? Or Is there something that our cloud-code needs to do to avoid seeing this error? Please share your thoughts on this. |
We are running on node chef, Our code is also now breaking. The issue appears that if we make any database queries from server code, cloud function or from express we get the fore mentioned error. If we call queries from JS client - all works find. If we do anything server side we get the error. We have tried removing our app.js require so that our express set-up is removed, this did not fix the issue. Can anybody help with this? at Layer.handle as handle_request |
Seeing same error as well. AWS ElastBeanstalk, t2.micro, 64bit Amazon Linux 2016.03 v2.1.3, node version 4.4.6 (perhaps that's the issue?). Errors are seen after running a cloud function, but my app still receives a valid response...
|
The fix seem pretty trivial as it looks like it originates from one of our middleware that's run after the cloud functions. As you have the error, can any of you work on a fix? |
We have rolled back the last update which has fixed the error. Not sure how we fix it, seems any cloud function throws an error, but response is sent. |
@flovilmart thank you for the reply. Will try that and update. |
@flovilmart Thanks for the suggestion. I tried that branch you pointed us to but am still getting this error: Error: Can't set headers after they are sent. @tillifywebb @madkid66 Did it work for you both or are you still seeing the issue, too? |
@sprabs We have tried that suggestion but still seeing the issue. Thank you @flovilmart anything else we can try? Thank you |
This is related to middleware firing header indiscriminately even though a previous handler had already sent header. |
Why was #2338 merged? This seems like a pretty drastic change in behavior for those of us working on getting our self-hosted infrastructure set up. It appears that now our What's the recommendation here? |
@woodardj it was a bug to not have it, You should always call If you are having issues with this, there is more than likely something not quite right in the order of the The order is very important to
|
@flovilmart @blacha @woodardj @jeffjen @tillifywebb @sprabs Thank you |
@madkid66 Previously parse server was not running express sets up a list of handlers for each URL it handles, it will run that handler then wait for the handler to call given a simple setup like the one in my previous comment the handlers for /parse would look something like: Before this change, Parse would not call The two places I would look into where this problem could occur is in Cloud Functions calling Something like this would cause issues (you need to return after if (error) {
response.error(error);
}
response.success() The other area would be inside the express app. Take a look for any I haven't had this change break any of my apps (All deployed to ElasticBeanstalk), which would make me think that their might be some inconsistent code in your cloud-functions/express setup. If anyone has a simple example that breaks, I would love to get my hands on it. |
@blacha Thank you for the detailed explanation. Will look at our code and get back with any questions. |
I'm glad we are having an open discussion about this. This is frustrating for my team as we are developing and I would like to get to the bottom of this. Apologies in advance for my long response, but I want to make sure we are on the same page here. @blacha I'm not sure I understand your explanation about our Cloud Code being the issue, so let me provide details about my situation (that looks like at least four independent people are also complaining about):
Based on this analysis (unless I am missing something), I don't think our Cloud Code is the culprit. Also, I think we all already know this, and it's been verified by several others, but when the commit in question is reverted, everything is just fine. We don't see the errors. Please let me know if there is anything else we should check... @tillifywebb @madkid66 @woodardj Please feel free to add, if there's anything I missed based on your own deployments. I think we all are in agreement that this needs to be fixed one way or another. Whether it's reverting this change or coming up with a solution on top of this merge... @flovilmart Obviously, we can't be having these errors in production. It's affecting several of us on the GitHub issue (and probably more who haven't noticed it, yet). Please let us know how you suggest we proceed with this. |
@sprabs Would you be able to take your simplest failing Cloud Code function and remove functionality until it does as little as possible but still reproduces the bug? AFAIK The backend for Cloud Code on parse.com does not use Express so we will not see this kind of error there. If we know the cause of the issue we can hopefully figure out a way for parse-server to be consistent with parse.com while at the same time being valid Express middleware. |
@steven-supersolid @blacha @flovilmart It's happening for even a pretty simple Cloud Code method (from our main.js) without any promise chains. I'll just reproduce my code so you have the same info... Here's a Cloud Code snippet: Parse.Cloud.define("forceUpdateCheck", function(request, response) {
var appVersion = request.params.appVersion;
var deviceType = request.params.deviceType;
var forceUpdateBool = "false"; //initialize to false to be safe
var constantsQuery = new Parse.Query("Constants");
constantsQuery.equalTo("name", "lastSupportedVersionNumber");
constantsQuery.first({
success: function(constantValue) {
if (constantValue && constantValue != undefined) {
var lastSupportedVersionNumber = (constantValue.get("valuesByDevice"))[deviceType]["versionNumber"];
var updateMessage = (constantValue.get("valuesByDevice"))[deviceType]["message"]
// massaging the version number to make it ordinal
var adjustedLastSupportedVersionNumber = Number(lastSupportedVersionNumber.replace(/\./g, ''));
var adjustedAppVersionNumber = Number(appVersion.replace(/\./g, ''));
if (adjustedAppVersionNumber < adjustedLastSupportedVersionNumber) {
forceUpdateBool = "true";
}
}
// return force update metadata to the client
if (forceUpdateBool == "true") {
response.success({"forceUpdateBool": forceUpdateBool, "updateMessage": updateMessage});
} else {
response.success({"forceUpdateBool": forceUpdateBool});
}
},
error: function(error) {
response.error("forceUpdateCheck method failed with error: " + error.message);
}
});
}); Here's the error:
For completion, I was also able to confirm that even with VERBOSE not enabled on my AWS Elastic Beanstalk app, I still see the error (above). |
@sprabs I updated your comment to have formatting (So it is easier for me to read) Ill try and reproduce your issue from my local instance today. |
I am having exactly the same issue. Creating dummy CloudCode, it seems to return the error whenever there is a promise involved. Returning any item without a promise doesn't seem to throw the error. This includes any Parse Queries. I have stripped back my express app to only include mounting the Parse API and the result is the same. Any cloud code containing a promise crashes the app. |
Does #2417 fix this problem? |
@blacha Since I had same issue, I tried using the fix you suggested above. But, I am still seeing the errors. Thank you for your suggestion. Error: Can't set headers after they are sent.
Error: Can't set headers after they are sent.
|
I believe this is the same problem as #2389 |
@flovilmart can you please comment on what I should try or can anything be added in the parse-server code to fix this so that all affected don't have to individually come up with a solution. Thank you |
@flovilmart could you please spare few minutes to provide your valuable suggestion/comments with a fix for this issue. Just that several are running into the same problem. Thank you. |
I am getting this issue as well, with trying to send a Push Notification through Cloud Code: Error: Can't set headers after they are sent. I cant use any type of code in Cloud Code without getting it to throw this error. |
Hello, @flovilmart. I just forked "parse-server-example" and made few modifications (added two routes)
and then later:
The error is going to be the same as listed:
My best regards. |
@rgipd can you provide what's in the |
Ok, @flovilmart, it's below. My current path is /tmp/parse-server-example:
How reproduce with my parse-server-example repository:
then:
Regards. |
Did you register your routes before of after parse-server? |
It's after, just like parse-example-server guideline. Check my index.js in my repository, but here is it:
PS: I updated the last answer with steps to reproduce. |
@flovilmart I just test with the routers before the parse-server and the result is the same:
|
I'm not sure what the problem is also note that the fix introduced here: #2475 has not been released yet |
I've been doing some investigation as can reproduce locally with parse-server master. The issue can be reproduced with the cli. I added debug in node_modules/express/lib/response.js
I ran the following with a valid access token:
And got a valid response:
The error is still displayed on the console log:
The final valid header is
After this, PromiseRouter.makeExpressHandler is returning next() at line 181. The 1st invalid header is
Which seems to come from ParseServer.constructor at line 296:
What is strange is that doing a user get gives no such error:
In this case the server log looks like:
The code in handleMe does not seem responsible as replacing this still reproduces the error. |
Nice investigation! That will probably help track down the issue. Odd that some end points don't reproduce the issue |
Probing a little more, there seems to be some interference from the other route mounted on /users/ in UsersRouter. Disabling /users/:objectId removes the error. Not sure if this is related.
I thought the problem may have been because /users/me matches the first route, then matches the 2nd with a user id of 'me'. I put some debug at the top of handleGet though and was not called when the error occurs. Almost out of ideas now. |
That may well be the case... we should do the handleMe in the same handler of the objectId |
@flovilmart , just a question, this fix is already in 2.2.18 or just in the master commit? |
Just on master |
Ok, thanks. Just to inform, the error still occurs in master (same code, same error)
|
Which endpoint are you calling? |
First I call register
The output is going to be fine, without errors.
with this code:
P.S.: Even using another nodejs library like request (than Parse.Cloud.httpRequest) the error is the same. Regards. |
How you you setup parse-server on the master branch? |
With this link: https://github.com/ParsePlatform/parse-server/wiki/Development-Guide This commands:
I will try another time in other machine. |
ok... that's odd, I don't have it with the unit tests... |
Maybe the problem can be with my machine configuration with npm packages. I couldn't test in another machine. Thank you. |
@flovilmart Sorry if I've missed something in this crazy thread, but I'm getting this on parse-server
|
We pulled parse-server code from master yesterday and while using that code, we notice the following stack trace in log for all the cloud calls being made. Anyone else seeing this? Also, any suggestions, tips for resolving this are appreciated. Thank you.
The text was updated successfully, but these errors were encountered: