Duplicate calls to cloud function
Using the parse-server with visual studio code debugger, in case a cloud function take more then ~30-40 seconds the method is called again.
This can be easily reproduce by adding a breakpoint at the beginning of the method and continue after ~30-40 seconds.
This also happen in our production server, we notice some of the methods are called twice.
Expected Results
Time out exception or some error
Actual Outcome
Method is called again.
Environment Setup
- Server
- parse-server version: 2.2.16
- Operating System: localhost is mac
- Localhost or remote server? both local and Azure
- Database
- MongoDB version: 3.0.12 (on mLab)
Can you include more information? What does the Cloud function look like? Does it happen with the simplest Cloud function (e.g. return immediately)? Basically, we'll need a solid list of repro steps.
I am experience same thing here
I've noticed something similar as well. Sometimes it can be less than 30 seconds, too.
It is not reproduce with simplest cloud function that return immediately but it is reproduce on this simple function: Parse.Cloud.define("userAPI_create_book", function (request, response) { var existingBookQuery = new Parse.Query("Book"); existingBookQuery.equalTo("completed", false);
existingBookQuery.first()
.always(function (existingBook)
{
response.success("ok");
});
});
if you add a break point at the beginning of the method and wait ~40 seconds and continue to run the break point will hit again. (I use visual studio code debugger but i guess it will happen in all debuggers since we see this issue in our production environment - we notice the side effects of the duplicate calls))
What client are you using? If you're using the iOS, android or JS SDK, they have retry mechanisms for calls that take longer than a certain amount. After a certain amount of seconds (usually 30), the reverse proxy (provided by heroky, AWS, GAE etc...) in the front of your parse-serverinstallation may drop the request too.
Can you confirm in anyway that those are not the clients re-trying the requests? Note that inside CloudCode, the JS client is using HTTP to communicate with parse-server, not only increasing by a small amount the overhead but also increasing the number of open connections to your server.
As a general rule, if your client need to wait more than 30s for a function to compute, he may hit the same button again, therefore re-sending, and that leads to a bad user experience. You may wanna refactor your code in order to 'enqueue' the work to be done in your cloud function and respond early. Unlike parse.com, the async functions that you run in cloud code won't be killed when responding to the client.
// this would perfectly work, on parse-server, not on parse.com
Parse.Cloud.define('somethingVeryLoong', (req, res) => {
res.success('OK');
setTimeout(function() {
// do something in 30s
}, 30000);
doSomethingVeryLong().then(() => {
// this will be called too, after the res.success('')
console.log('Done!');
});
});
As @hramos mentioned, we need solid repro steps to make sure this is a bug in parse-server and not an expected retry mechanism that would take over in case of long running requests.
@flovilmart The above does not work. Basically my use case is, I need to call a cloud function that sends push notification via GCM server to some 25 clients. Nothing works after res.success() and afterSave triggers multiple calls for the same client. Very weird.
Not sure if your comment is relevant given the lack of initial STR and also that this issue has been closed over a year ago