Heroku上的socket.io一直给我H15空闲连接错误

时间:2016-06-25 18:22:15

标签: node.js express heroku socket.io

我正在使用socket.io来处理当前正在制作的应用(在heroku上)并且我一直收到这些错误。似乎所有东西仍然可以正常工作,但我的日志充满了错误。

Jun 23 15:33:00 fixtrackapi heroku/router: at=error code=H15 desc="Idle connection" method=GET path="/ws/?EIO=3&transport=websocket&sid=ZS_zSjEfTAkmA8GMAAAC" host=api.myurl.com request_id=18ca3817-009a-419f-8ef3-c598bc866bb4 fwd="84.194.46.28,54.155.253.188" dyno=web.1 connect=0ms service=119082ms status=503 bytes=189 
Jun 23 15:33:01 fixtrackapp heroku/router: at=error code=H15 desc="Idle connection" method=GET path="/ws/?EIO=3&transport=websocket&sid=ZS_zSjEfTAkmA8GMAAAC" host=demo.myurl.com request_id=18ca3817-009a-419f-8ef3-c598bc866bb4 fwd="84.194.46.28" dyno=web.1 connect=0ms service=119741ms status=503 bytes=205 
Jun 23 15:34:10 fixtrackapi heroku/router: at=error code=H15 desc="Idle connection" method=GET path="/ws/?EIO=3&transport=websocket&sid=w_vK_zsJv7BY9j7qAAAD" host=api.myurl.com request_id=d0a07db1-1cd1-4b3c-8229-c0fbc32a39db fwd="84.194.46.28,54.155.253.188" dyno=web.1 connect=0ms service=55231ms status=503 bytes=183 
Jun 23 15:34:11 fixtrackapp heroku/router: at=error code=H15 desc="Idle connection" method=GET path="/ws/?EIO=3&transport=websocket&sid=w_vK_zsJv7BY9j7qAAAD" host=demo.myurl.com request_id=d0a07db1-1cd1-4b3c-8229-c0fbc32a39db fwd="84.194.46.28" dyno=web.1 connect=0ms service=55941ms status=503 bytes=199 

正如您所看到的,有2个heroku应用同时报告错误,这是因为' fixtrackapp'将socket.io请求代理到我的api服务器(' fixtrackapi')。

客户代码:

const socket = io('', { path: '/ws' });

这是代理代码:

const proxy = httpProxy.createProxyServer({
  target: targetUrl,
  changeOrigin: true,
  ws: true
});
app.use('/api', (req, res) => {
  proxy.web(req, res, {target: targetUrl + '/v1'});
});

app.use('/ws', (req, res) => {
  proxy.web(req, res, {target: targetUrl + '/ws'});
});

Api服务器代码:

const app = express();
const server = new http.Server(app);
const io = socketio(server);
io.path('/ws');
const runnable = app.listen(port, () => console.log(`API running on port ${port}`));
io.listen(runnable);

我还尝试过使用setinterval在客户端上运行我自己的活着,然后发送了一个' ping'每8秒一次。但我仍然有错误(虽然有时看起来我的错误很少)。

知道可能导致这种情况的原因是什么?

提前致谢

0 个答案:

没有答案