Socket.io heroku request timeout

I use Socket.IO (latest version 1.3.6) with Node.js on the Heroku record, I am developing the main chat application created using express.js. It works very well for most clients connected to the chat, but for one client I get a few errors from my hero:

heroku router - - at=error code=H12 desc="Request timeout" method=GET path="/socket.io/?EIO=3&transport=polling&t=1442928164852-20&sid=OIjnoxv2RqP3ijBnAAAA" host=xxx.herokuapp.com fwd="x.x.x.x" dyno=web.1 connect=0ms service=30000ms status=503 bytes=0
heroku router - - at=error code=H12 desc="Request timeout" method=GET path="/socket.io/?EIO=3&transport=polling&t=1442924841606-16&sid=5yukgKd2YUl75t1rAAAI" host=xxx.herokuapp.com fwd="x.x.x.x" dyno=web.1 connect=1ms service=30000ms status=503 bytes=0
...

It can send and receive messages without problems, but, for example, when it closes its browser tab, the disconnect event does not start and the connection timeout on the server side. This client is behind the corporate web proxy.

Here is the server code:

var heartbeatInterval = 50000;

socket.init = function( io ) {

    function sendHeartbeat() {
        setTimeout( sendHeartbeat, heartbeatInterval );
        io.emit('ping', { beat : 1 });
    }

    io.on('connection', function( socket ) {

        var session = socket.handshake.session;
        var dateFormat = 'DD/MM à HH:mm:ss'
        var time = moment().tz('Europe/Paris').format( dateFormat );

        if( session.user ) {
            users.exist(session.user.name, function( exist ) {
                if( ! exist ) {
                    users.add( session.user );
                    users.list(function( usersList ) {
                        io.emit('user_new');
                        addBotMessage(io, time, session.user.name + " connected");
                        async.eachSeries(usersList, function( user, next ) {
                            io.emit('user_connected', user);
                            next();
                        }, function() {
                            socket.on('pong', function( data ) {
                                debug('Pong received from client');
                            });
                            socket.on('message', function( message ) {
                                time = moment().tz('Europe/Paris').format( dateFormat );
                                if( message && message.length <= 1000 )
                                    addMessage(io, time, session.user, marked( message ));
                            });
                            socket.on('disconnect', function() {
                                users.remove( session.user.name );
                                time = moment().tz('Europe/Paris').format( dateFormat );
                                io.emit('user_disconnected', session.user.id);
                                addBotMessage(io, time, session.user.name + " disconnected");
                            });
                        });
                    });
                } else {
                    io.to( socket.id ).emit('already_connected');
                }
            });
        }
    });

    setTimeout( sendHeartbeat, heartbeatInterval );
};

I do not know how to fix this problem, any idea / advice?

+4
source share
1

wrap socket.io http

0

Source: https://habr.com/ru/post/1608532/


All Articles