我们有一个在SocketIO上运行的NodeJS应用程序,并在heroku上进行集群。为了让SocketIO正常工作,我们使用这里讨论的redis适配器:https://socket.io/docs/using-multiple-nodes/。
然后,我们实现了粘性会话,如粘性会话文档中所示:https://github.com/elad/node-cluster-socket.io。
事实证明,当我们部署到Heroku时,其中的connection.remoteAddress:
// Create the outside facing server listening on our port.
var server = net.createServer({ pauseOnConnect: true }, function(connection) {
// We received a connection and need to pass it to the appropriate
// worker. Get the worker for this connection's source IP and pass
// it the connection.
var index = worker_index(connection.remoteAddress, num_processes);
var worker = workers[index];
worker.send('sticky-session:connection', connection);
}).listen(port);实际上是某个heroku路由服务器的IP地址,而不是客户端IP。我已经看到请求头"x-forwarded-for“可以用来获取客户端IP,但是当我们以这种方式暂停连接时,我们甚至还没有这些头?
发布于 2018-12-28 04:33:33
我们到处寻找解决方案,但显然没有好的解决方案。
以下是一些更好的建议:
https://github.com/indutny/sticky-session/issues/6
https://github.com/indutny/sticky-session/pull/45
它们在性能方面似乎都不是很好,因此我们最终将SocketIO通信改为只使用Websockets。这消除了所有粘性会话的需要。
https://stackoverflow.com/questions/53938147
复制相似问题