Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js Web Socket H15 Idle Connection timeout on Heroku

We run a Node.js and Express application on Heroku that uses the ws library for realtime web sockets. Below is a screen shot of the numerous H15 timeout's that we are seeing.

enter image description here

I've read that Heroku terminates any idle connection after 55 seconds but our sockets send ping-pong back and forth every 5 seconds when the connection is open. A piece of the server code is below:

var _this = this;

this.server.on('connection', function(ws){

    // check for a ping, respond with pong
    ws.on('message', function(data){
        data = data.toString('utf8');
        if (data === PING) {
            ws.send(PONG);
        }
    });

    ws.on('close', function(err){
        TL.logger.info('Socket closed: '+path);
        _this.sockets = _.filter(_this.sockets, function(_ws){
            return ws != _ws;
        });
    });

    ws.on('error', function(err){
        TL.logger.info('Socket error: '+path);
        _this.sockets = _.filter(_this.sockets, function(_ws){
            return ws != _ws;
        });
    });

    _this.sockets.push(ws);
});

And here's a picture of client side socket in chrome:

enter image description here

Any idea's how to prevent the idle connection?

like image 906
Andrew Avatar asked Sep 09 '14 00:09

Andrew


1 Answers

disclosure: I'm the Node.js platform owner at Heroku.

Are you seeing this on the client side? Or just the error-reporting dashboard?

I'd recommend focusing on reproducing the errors on at least one client, to see if there's actually any impact. Otherwise, you may be wasting time debugging false positives.

If you do decide to continue debugging, you may want to install a free papertrail / nodetime / new relic / strongloop addon to figure out exactly which requests are triggering the H15s.

like image 74
hunterloftis Avatar answered Oct 22 '22 22:10

hunterloftis