Jurgo Boemo
Jurgo Boemo

Reputation: 1768

heroku Idle connection timeout on heroku socket.io server based

Sometimes my socket server raise the following problem:

Here the heroku log:

heroku[router]: at=error code=H15 desc="Idle connection" method=GET path=/socket.io/1/websocket/RcjG0Zjot1U3uwLWX9SI 
host=www.*********.** request_id=69f5aa39-255b-4871-a928-1548ef2fdd4f 
fwd="217.200.201.210" dyno=web.1 connect=0 service=306473 status=503 bytes=870

I'm using socket.io library version 0.9.x and node 0.8.x. It's hosted on heroku with the websocket activated (heroku labs:enable websockets -a myapp). I'm not using xhr-polling

Here's how I've implemented the socket server:

var httpServer = http.createServer(function(request, response) {
  var pathname = url.parse(request.url).pathname;
  if(pathname == "/") pathname = "index.html";
  if(pathname.indexOf("/chat/") != -1  ) pathname = "index.html";
  var filename = path.join(process.cwd(), 'public', pathname);
  path.exists(filename, function(exists) {
    if(!exists) {
      response.writeHead(404, { "Content-Type": "text/plain" });
      response.write("404 Not Found");
      response.end();
      return;
    }
    response.writeHead(200, { 'Content-Type': mime.lookup(filename) });
    fs.createReadStream(filename, {
      'flags': 'r',
      'encoding': 'binary',
      'mode': 0666,
      'bufferSize': 4 * 1024
    }).addListener("data", function(chunk) {
      response.write(chunk, 'binary');
    }).addListener("close", function() {
      response.end();
    });
  });
});


socket_calls = new socket_calls(webSocket, io, connectedUsers,clients );
webSocket.sockets.on('connection',socket_calls.socket_callback_func );
httpServer.listen(process.env.PORT || 8080, "0.0.0.0");

This problem seems to be present only on 3g connection and it's reported by some clients who sistematically can't connect to the server.

I've tryed to reproduce the problem on several devices with 3g connection and wi-fi connection using "network link conditioner" to simulate a bad connection, but I can't reproduce the error.

Upvotes: 3

Views: 2320

Answers (1)

Jurgo Boemo
Jurgo Boemo

Reputation: 1768

I've solved it. The problem was present only on 3g connection with TIM career.

I've disabled the websocket support from heroku command line tools and I've enabled xhr-polling on socket.io.

Upvotes: 1

Related Questions