heroku基于heroku socket.io服务器的空闲连接超时

有时我的套接字服务器引发了以下问题:

这里的heroku日志:

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 

我使用socket.io库版本0.9.x和节点0.8.x. 它是在heroku上启动的websocket(heroku实验:启用websockets -a myapp)。 我没有使用xhr-polling

以下是我如何实现套接字服务器:

 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"); 

这个问题似乎只存在于3G连接上,而且有些客户端无法连接到服务器。

我已经尝试使用3g连接和Wi-Fi连接使用“networking链接调节器”模拟一个错误的连接,但我不能重现错误在几个设备上重现问题。

我解决了它。 这个问题只存在于TIM职业生涯的3g连接上。

我已经禁用了heroku命令行工具的websocket支持,并且在socket.io上启用了xhr-polling。