2016-05-24 5 views
5

snlamm私はRailsアプリケーションで複数のウェブソケットチャネルを実装する際に問題があります。Rails 5 Webソケット用に複数のチャネルを実行する際にActionCableの問題が発生する

Started GET "/cable" for ::1 at 2016-05-24 11:42:16 -0400 
Started GET "/cable/" [WebSocket] for ::1 at 2016-05-24 11:42:16 -0400 
Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket) 

注:私達のブラウザのコンソールにエラーをスローしないエラーは、サーバーが以下の応答の後にフリーズするということです。私たちはChrome v 50.0(最新版)を使用しています。

は、しかし、矛盾基づいて我々は、ブラウザとサーバーの両方を再起動した場合、我々が得る:

Started GET "/cable" for ::1 at 2016-05-24 11:45:54 -0400 
Started GET "/cable/" [WebSocket] for ::1 at 2016-05-24 11:45:54 -0400 
Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket) 
ItemsChannel is transmitting the subscription confirmation 
ItemsChannel is streaming from items 
MessagesChannel is transmitting the subscription confirmation 
MessagesChannel is streaming from messages 

、すべてが正常に動作します。

この修正プログラムは一貫性がなく、サーバーがフリーズすることがよくあります。 1つのチャンネルしか稼動していないときに問題はないことに気付きました。

ここでは、追加した2つのチャンネルの1つであるitemsチャンネルのコードを示します。両方のチャンネルのためのコードは、ほぼ同一である。

mount ActionCable.server => '/cable' 

チャネル/ application_cable/channel.rb

module ApplicationCable 
    class Channel < ActionCable::Channel::Base 
    end 
end 

チャネル/ application_cable/connection.rb

経路

module ApplicationCable class Connection < ActionCable::Connection::Base end end 

チャネル/ items_channel.rb

class ItemsChannel < ApplicationCable::Channel 
    def subscribed 
    stream_from 'items' 
    end 
end 

ビュー/注文/ show.html.erb

これはアイテムを示すに取り付けられたチャネルのための私達の図です。

<div id="item-list"> 
     <h2>Items: <% @order.items.each do |item| %></h2> 
     <li><%= item.name %> - $<%= item.cost %></li> 
     <% end %> 
    </div> 
    </ol> 
    <div id="item-errors"> 
    </div> 
    <br> 
    <h3>Time until ordered: <%= ((@order.expiration - @order.date_ordered)/60).round %> minutes</h3></div> 

    <%= form_for @item, remote: true do |f| %> 
    <%= f.hidden_field :order_id, value: @order.id, id: "order-id" %> 
    <span id='item-content-reset'> 
    Item name: <%= f.text_field :name, id: 'item-name' %> 
    Cost: <%= f.text_field :cost, id: 'item-cost' %> 
    </span> 
    <%= f.submit "Add Item", :id => 'item-create-btn' %> 
    <% end %> 
</div> 

コントローラ/ items_controller.rb

class ItemsController < ApplicationController 
    def create 
    @item = Item.new(item_params) 
    @item.user = @current_user 
    if @item.save 
     ActionCable.server.broadcast 'items', 
     name: @item.name, 
     cost: @item.cost 
     head :ok 
    else 
     error_message = @item.errors.messages 
     render partial: 'shared/errors', locals: { errors: flash.now[:alert] = "Item " + error_message[:name][0] } 
    end 
    end 

    private 

    def item_params 
    params.require(:item).permit(:order_id, :cost, :name) 
    end 
end 

資産/

//= require jquery 
//= require bootstrap-sprockets 
//= require jquery_ujs 
//= require bootstrap-switch 
// require jquery.session 
// require turbolinks 
//= require_tree . 

資産/ JavaScriptの/チャンネル/ chatrooms.js

application.jsサーバー我々は、ps auxをを終了した後
//= require action_cable 
//= require_self 
//= require_tree . 

this.App = {}; 

App.cable = ActionCable.createConsumer("/cable"); 

資産/ JavaScriptの/チャンネル/ items.js

App.items = App.cable.subscriptions.create('ItemsChannel', { 
    received: function(data) { 
    return $("#item-list").append(this.renderItem(data)); 
    }, 
    renderItem: function(data) { 
    return "<li> " + data.name + " - " + "$" + data.cost + "</li>"; 
    } 
}); 

|レール、ルビー、プーマ、赤目のためのgrepであり、それらはすべて正常に閉じた(すなわち、ゾンビプロセスはなかった)。何が原因でサーバーがフリーズする可能性がありますか?

答えて

1

これは、次のバグ(Actioncable deadlock with multiple channels #24741)のように聞こえます。上記のリンクでパッチを入手することができます。開発中であれば、私のために働いたconfig.eager_load = trueをdevelopment.rbに設定してみることもできます。

関連する問題