How to avoid an heroku request timeout?

752 views Asked by At

I have deployed my node.js service to Heroku but facing a request timeout error: https://devcenter.heroku.com/articles/error-codes#h12-request-timeout.

How can I avoid this or fix this? Is this an error in the node.js service or can I change this in the Heroku Dyno settings?

This is showing in the logs:

2015-06-21T00:48:01.965583+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/" host=damp-meadow-5935.herokuapp.com request_id=4ca2e2a9-b983-4cec-a8e1-cd7e73c5b274 fwd="54.157.11.252" dyno=web.1 connect=2ms service=30007ms status=503 bytes=0

My node.js service looks like this:

// set up ======================================================================
var express = require('express');
var app = express();                               // create our app w/ express
var port = process.env.PORT || 5001;                // set the port

var bodyParser = require('body-parser');
var methodOverride = require('method-override')
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));

app.use(function (req, res, next) {
    //the code hits this point!
    var data = '';
    req.on('data', function (chunk) {
        data += chunk;
    });
    req.on('end', function () {
        req.rawBody = data;
        next();
    });
    //console.log(data);
});
app.use(methodOverride());
// routes ======================================================================
require('./routes.js')(app);

var server = app.listen(port);

and:

var _ = require('underscore');

module.exports = function (app) {
    app.post('/', function (req, res) {
        console.log('testing entering /api/filter');
        var Validator = require('jsonschema').Validator;
        var v = new Validator();
        var jso = req.rawBody;
        var newjso = JSON.parse(req.rawBody);
        var schema={
            "description": "A payload",
            "type": "object"
        }

        var result = v.validate(newjso,schema);

        if (result.errors.length > 0) {
            res.setHeader('content-type', 'application/json');
            res.status(400);
            res.json({
                "error": "Could not decode request: JSON parsing failed"
            });
        }
        else
        {
            var resp = _.filter(_.where(newjso.payload, {drm: true}), function (item) {
                return item.episodeCount > 0
            });

            var newArray = [];
            resp.forEach(function (item) {
                var newItem = _.pick(item, 'image', 'slug', 'title');
                newItem.image = _.propertyOf(newItem.image)('showImage');
                newArray.push(newItem);
            })

            res.setHeader('content-type', 'application/json');
            res.status(200);
            res.json(newArray);
        }

        console.log('testing einde');    })
}
0

There are 0 answers