I am getting the Heroku H12 - Request timeout error for no apparent reason

北城余情 提交于 2019-12-10 12:10:55

问题


In my parse server I have a class called Stats which contains the column timeScore (number)

I am using cloud code to update all 250k rows in the column timeScore.

My code works well except for the fact that I get the following H12 - Request timeout error for no apparent reason.

heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/parse/functions/timeScore

I get the timeout error regardless of what batchSize I choose and I get it every 30 seconds. I get it for a total of 5 times. After the 5th time I dont get it anymore and the process continues and finishes without any issues or errors. I get the 5th and last error at around 2.5 minutes into the process (30seconds*5).The whole process takes about 14 minutes. These timeout errors does not effect the process in any way. All 250k objects are updated and saved regardless of the selected batchSize and despite the timeout errors.

I thought maybe because I never call results.error or results.success the server thinks I am still doing some work and shows the error. However I updated my code as seen below to include them and I still get the timeout errors.

The problem is after each timeout error processBatch() is called once again from the beggining. Since I get 5 timeout errors processBatch() gets called 5 times. So after the 5th timeout error there are 5 processBatch() functions running simultaneously (I confirmed this with logs). This makes the process take much longer that it should take.

I am not performing any long running actions. I am just updating and saving data on my parse server.

Here is my code:

var _ = require("underscore");
Parse.Cloud.define("timeScore", function(request, response) {
var counter = 0;
function processBatch(query, batchSize, startingAt, process) {
    query.limit(batchSize);
    query.skip(startingAt);

    return query.find().then(results => {

        return process(results).then(() => results.length);
    }).then(length => {

        return (length === batchSize)? processBatch(query, batchSize, startingAt+length, process) : {};
    });
}

function setTimeScores(stats) {
        console.log("LENGTH " + stats.length);
    _.each(stats, stat => {

        counter ++;
        stat.set("timeScore", counter);

    });
    return Parse.Object.saveAll(stats);
}

var query = new Parse.Query("Stats");

processBatch(query, 1000, 0, setTimeScores).then(results => {
        response.success(results);
    }).catch(error => {
        response.error(error);
    });

});

Here is how I call it

#!/usr/bin/env node
var Parse = require("parse/node");
Parse.initialize("xx",   "xx");
Parse.serverURL = "http://randomapp.herokuapp.com/parse";
Parse.Cloud.run('timeScore');

What is causing the heroku timeout errors I am getting? How do I fix it?

来源:https://stackoverflow.com/questions/51377100/i-am-getting-the-heroku-h12-request-timeout-error-for-no-apparent-reason

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!