10

So I want to fetch a large amount of data on Parse, a good solution I found is to make a recursive function: when the data are successfully found, launch another request. The way I'm doing it is pretty simple:

var containedLimit = 1000, // Also tried with 500, 300, and 100
    parseUsersWaiting = {
        // A lot of Users
    },
    parseUsers = {}, // Recipt for Users
    getPlayers = function (containedIn) {        
        var count = 0;

        if (containedIn == undefined) {
            containedIn = [];

            for (var i in parseUsersWaiting) {
                count++;
                if (count > containedLimit) {
                    break;
                }

                containedIn.push(parseUsersWaiting[i].id);
                delete parseUsersWaiting[i];
            }
        }

        var UserObject = Parse.Object.extend('User'),
            UserQuery = new Parse.Query(UserObject);

        UserQuery.limit(containedLimit);

        UserQuery.containedIn('objectId', containedIn);
        UserQuery.find({
            success: function (results) {
                if (results) {
                    for (var i in results) {
                        if (parseUsers[results[i].id] == undefined) {
                            parseUsers[results[i].id] = results[i];
                        }

                        // Other stuff

                        if (results.length < containedLimit) {
                            // End of process
                        } else {
                            getPlayers();
                        }
                    }
                } else {
                    // Looks like an end of process too
                }
            }, error: function (error) {
                console.log(error.message);
                getPlayers(containedIn);
            }
        });
    };

Now, here is what I would like to call the "issue": it happen, very frequently, that the "error" callback is launched with this:

Received an error with invalid JSON from Parse: Error: getaddrinfo ENOTFOUND api.parse.com
at errnoException (dns.js:44:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:94:26)

(With code 107, of course) So I searched on the Parse Documentation, and it says the exact same thing: "Received an error with invalid JSON". Yeah.

I'm using the Parse SDK provided by Parse.com (npm install parse)

I also tried to modify a bit the Parse code with replacing the host key by 'hostname' on line 361 of the file parse/node_modules/xmlhttprequest/lib/XMLHttpRequest.js (Parse package version: 1.5.0), and it didn't worked, so I removed my changes.

(By the way, I found a solution talking about using ulimit to change memory usage limit that could solve the problem, but actually, I haven't the necessary rights to execute this command)

2
  • What was the ulimit solution? Commented Aug 21, 2015 at 11:31
  • I found it here, but actually it's not the same error Commented Aug 27, 2015 at 16:45

1 Answer 1

4
+25

This error occurs when it can not connect to the API (technically when it cannot lookup the IP address of the API server). Perhaps your internet connection was lost for a brief moment or their SDK server were unavailable (or maybe the server is denying your request due to rate limits).

Either way it is good to code some resilience into your application. I see your on error function retries the API call, but perhaps it would be worth adding a timeout before you do that to give the problem a chance to recover?

    error: function (error) {
        console.log(error.message);
        setTimeout(getPlayers, 10000, containedIn);
    }

If the sever is rate limiting your requests, this will also help.

Sign up to request clarification or add additional context in comments.

5 Comments

The Parse server has a high rate limit (something like 100/s), also, I'm executing my script on an OVH server (so it should not go offline, plus, I'm connecting through SSH and I'm seeing the errors, so the server is, actually, not going offline) this error is happening a lot of time (It can happen something like each 15 requests).
Did the timeout help?
Can you add Parse.prototype._api_host = '54.84.64.193' to make sure it is not a dns issue? I think that will work, or you could add it to your /etc/hosts
After searching into the parse/build/parse-latest.js, there are no declaration for this var. Anyway, I tried your solution before a Parse.initialize(), it didn't worked (Cannot set property '_api_host' of undefined), so I tried directly with Parse._api_host = '54.84.64.193' and it didn't worked neither, also, of course, the timeout could work, but I’m trying to avoid this error completely
sudo nano /etc/hosts and add a line at the end saying api.parse.com 54.84.64.193 just to rule out the dns as an issue

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.