ActionCable超时 - Heroku上的"空闲连接"

Jac*_*ins 12 ruby-on-rails heroku ruby-on-rails-5 actioncable

我们已经在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
Run Code Online (Sandbox Code Playgroud)

我相信我们的设置非常标准,并且紧跟ActionCable的Rails文档:

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
Run Code Online (Sandbox Code Playgroud)

我们有三个这样简单的渠道:

class ActivitiesChannel < ApplicationCable::Channel  

  def subscribed
    stream_from "activities_#{current_user.id}" if current_user
  end
end
Run Code Online (Sandbox Code Playgroud)

编辑添加 - Javascript代码:

app/assets/javascripts/channels/setup.js:

//= require cable

this.App || (this.App = {});
App.cable = ActionCable.createConsumer(); 
Run Code Online (Sandbox Code Playgroud)

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);
  }
});
Run Code Online (Sandbox Code Playgroud)

我对ActionCable和WebSockets相当新,所以我不确定如何解决这个问题.我们使用Ruby 2.3.1运行Rails 5.0.0.1

任何帮助,上下文或疑难解答提示将不胜感激!

小智 0

你使用heroku的哪个计划?如果空闲 - 不要忘记它在 30 分钟不活动后会休眠,这可能会导致一些 H15 错误(空闲连接...)