【发布时间】:2017-04-19 01:25:00
【问题描述】:
我们在 Heroku 上使用 ActionCable 已经有一段时间了,总体来说效果很好。但是,我们每天会多次看到H15 Idle Connection 错误。他们总是有path=/cable 和很长的service 时间,所以连接在一段时间内肯定是健康的。
Dec 2016 08:32:22.057 heroku router - - at=error code=H15 desc="Idle connection"
method=GET path="/cable" host=<our host> dyno=web.2 connect=1ms service=928755ms status=503
我相信我们的设置非常标准,并且紧跟 Rails 的 ActionCable 文档:
module ApplicationCable
class Connection < ActionCable::Connection::Base
identified_by :current_user
def connect
self.current_user = find_verified_user
end
protected
def find_verified_user
if current_user = User.find_by(id: cookies.signed[:user_id])
current_user
else
# reject_unauthorized_connection
end
end
end
end
我们有这样三个简单的渠道:
class ActivitiesChannel < ApplicationCable::Channel
def subscribed
stream_from "activities_#{current_user.id}" if current_user
end
end
编辑添加 - Javascript 代码:
app/assets/javascripts/channels/setup.js:
//= require cable
this.App || (this.App = {});
App.cable = ActionCable.createConsumer();
app/assets/javascripts/channels/notifications.js:
App.notifications = App.cable.subscriptions.create('NotificationsChannel', {
received: function(data) {
return this.showMessage(data);
},
showMessage: function(data) {
showNotice(data.message);
}
});
我对 ActionCable 和 WebSockets 还很陌生,所以我不确定如何解决这个问题。我们正在运行 Rails 5.0.0.1 和 Ruby 2.3.1
非常感谢任何帮助、上下文或故障排除提示!
【问题讨论】:
-
我有类似的 AC 设置,但我没有收到 H15 错误。你能显示初始化电缆连接的javascript吗?
-
@EmilKampp 我刚刚编辑添加了一些我们的 JavaScript 代码。提前致谢!
-
@JackCollins 我也遇到了同样的问题,你找到解决办法了吗?
-
@SurgePedroza 不,不幸的是还没有解决这个问题
-
我刚遇到这个问题。所有错误都来自同一用户。否则,交流电工作正常。 ??????
标签: ruby-on-rails heroku ruby-on-rails-5 actioncable