Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoBrainer fails to reset connection for ActionCable channel when rethinkDB crashes #237

Closed
as-gennadiy-n opened this issue Apr 4, 2017 · 2 comments

Comments

@as-gennadiy-n
Copy link

For example if we set up an ActionCable channel with NoBrainer and we are streaming data from rethinkDB's change(), and rethinkDB restarts, NoBrainer fails to reset a connection and tries to use an old, invalid one. Here are some rails logs:

2017-03-30T20:35:58+00:00 INFO: Started GET "/chats" for 195.191.175.244 at 2017-03-30 20:35:58 +0000
2017-03-30T20:35:58+00:00 INFO: Processing by ChatController#index as HTML
2017-03-30T20:35:58+00:00 INFO:   Rendering chat/index.html.haml within layouts/dashboard
2017-03-30T20:35:58+00:00 INFO:   Rendered layouts/_alert_notice_flash.haml (0.2ms)
2017-03-30T20:35:58+00:00 INFO:   Rendered layouts/_ribbon.html.erb (0.5ms)
2017-03-30T20:35:58+00:00 INFO:   Rendered chat/_message_thread.html.haml (0.4ms)
2017-03-30T20:35:58+00:00 INFO:   Rendered chat/_chat_list_united.html.haml (71.0ms)
2017-03-30T20:35:58+00:00 INFO:   Rendered chat/_chats_list.haml (72.2ms)
2017-03-30T20:35:58+00:00 INFO:   Rendered chat/_no_messages_found.html.haml (0.2ms)
2017-03-30T20:35:58+00:00 INFO:   Rendered message_templates/_variables.haml (0.5ms)
2017-03-30T20:35:58+00:00 INFO:   Rendered chat/_message_template_modal.html.haml (3.3ms)
2017-03-30T20:35:58+00:00 INFO:   Rendered chat/_chat_footer.html.haml (6.7ms)
2017-03-30T20:35:58+00:00 INFO:   Rendered chat/_chat_synchronize_dialog.haml (0.4ms)
2017-03-30T20:35:58+00:00 INFO:   Rendered message_templates/_upload.haml (0.7ms)
2017-03-30T20:35:58+00:00 INFO:   Rendered rdb/messages/_airbnb_message.haml (0.2ms)
2017-03-30T20:35:58+00:00 INFO:   Rendered rdb/messages/_email_message.haml (0.2ms)
2017-03-30T20:35:58+00:00 INFO:   Rendered rdb/messages/_status_message.haml (0.3ms)
2017-03-30T20:35:58+00:00 INFO:   Rendered rdb/messages/_message_templates.haml (1.3ms)
2017-03-30T20:35:58+00:00 INFO:   Rendered chat/_chat_body.haml (10.1ms)
2017-03-30T20:36:00+00:00 INFO: Started GET "/auth/login" for 50.112.95.211 at 2017-03-30 20:36:00 +0000
2017-03-30T20:36:00+00:00 INFO: Processing by Auth::SessionsController#new as */*
2017-03-30T20:36:00+00:00 INFO:   Rendering auth/sessions/new.html.erb within layouts/auth
2017-03-30T20:36:00+00:00 INFO:   Rendered auth/_header_regist.html.erb (0.3ms)
2017-03-30T20:36:00+00:00 INFO:   Rendered auth/_slider.html.erb (0.2ms)
2017-03-30T20:36:00+00:00 INFO:   Rendered auth/sessions/new.html.erb within layouts/auth (1.9ms)
2017-03-30T20:36:00+00:00 INFO:   Rendered layouts/_footer.html.erb (0.2ms)
2017-03-30T20:36:00+00:00 INFO:   Rendered layouts/_google_analytics.html.erb (0.1ms)
2017-03-30T20:36:00+00:00 INFO: Completed 200 OK in 10ms (Views: 3.4ms | ActiveRecord: 0.0ms)
2017-03-30T20:36:01+00:00 INFO:   Rendered chat/_chat_list_filter_form.html.haml (2577.8ms)
2017-03-30T20:36:01+00:00 INFO:   Rendered chat/_chat_list_filter_modal.html.haml (2578.2ms)
2017-03-30T20:36:01+00:00 INFO:   Rendered chat/index.html.haml within layouts/dashboard (2664.0ms)
2017-03-30T20:36:01+00:00 INFO:   Rendered layouts/_locale_select.html.haml (0.8ms)
2017-03-30T20:36:01+00:00 INFO:   Rendered layouts/_dashboard_header.html.erb (1.1ms)
2017-03-30T20:36:01+00:00 INFO:   Rendered layouts/_user_stats.html.haml (6.5ms)
2017-03-30T20:36:01+00:00 INFO:   Rendered layouts/_left_panel.html.haml (10.1ms)
2017-03-30T20:36:01+00:00 INFO:   Rendered layouts/_page_footer.html.erb (0.2ms)
2017-03-30T20:36:01+00:00 INFO:   Rendered layouts/_scripts.html.erb (0.1ms)
2017-03-30T20:36:01+00:00 INFO:   Rendered layouts/_logout_modal.html.erb (0.4ms)
2017-03-30T20:36:01+00:00 INFO:   Rendered layouts/_google_analytics.html.erb (0.1ms)
2017-03-30T20:36:01+00:00 INFO: Completed 200 OK in 2690ms (Views: 592.6ms | NoBrainer: 2085.6ms (read) | ActiveRecord: 0.0ms)
2017-03-30T20:36:01+00:00 INFO: Finished "/cable/" [WebSocket] for 195.191.175.244 at 2017-03-30 20:36:01 +0000
2017-03-30T20:36:03+00:00 INFO: Started POST "/chat/confirm_online" for 195.191.175.244 at 2017-03-30 20:36:03 +0000
2017-03-30T20:36:03+00:00 INFO: Processing by ChatController#confirm_online as */*
2017-03-30T20:36:03+00:00 INFO: Completed 200 OK in 24ms (NoBrainer: 14.1ms (write) | ActiveRecord: 0.0ms)
2017-03-30T20:36:03+00:00 INFO: Started GET "/cable" for 195.191.175.244 at 2017-03-30 20:36:03 +0000
2017-03-30T20:36:03+00:00 INFO: Started GET "/cable/" [WebSocket] for 195.191.175.244 at 2017-03-30 20:36:03 +0000
2017-03-30T20:36:03+00:00 INFO: Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: upgrade, HTTP_UPGRADE: websocket)
2017-03-30T20:36:03+00:00 INFO: Registered connection (Z2lkOi8vbWlucGFrdS1kYXNoYm9hcmQvVXNlci8xOTA1ZDk1OC1jODRmLTExZTYtODQ3MC0wNmMwMGVjMzIzMzE)
2017-03-30T20:36:04+00:00 INFO: ChatListChannel is transmitting the subscription confirmation
2017-03-30T20:36:04+00:00 INFO: ChatsSyncChannel is transmitting the subscription confirmation
2017-03-30T20:36:04+00:00 INFO: ChatMessagesChannel is transmitting the subscription confirmation
2017-03-30T20:36:04+00:00 INFO: UnreadThreadsChannel is transmitting the subscription confirmation
2017-03-30T20:36:04+00:00 INFO: ChatsSyncChannel#stream_channel_data
2017-03-30T20:36:04+00:00 ERROR: Could not execute command from {"command"=>"message", "identifier"=>"{\"channel\":\"ChatsSyncChannel\"}", "data"=>"{\"action\":\"stream_channel_data\"}"}) [RethinkDB::ReqlRuntimeError - Connection is closed.]: /opt/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/nobrainer_streams-0.2.0/lib/nobrainer_streams/rethinkdb_monkeypatch.rb:258:in `run' | /opt/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/nobrainer_streams-0.2.0/lib/nobrainer_streams/rethinkdb_monkeypatch.rb:249:in `block in async_run' | /opt/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/nobrainer_streams-0.2.0/lib/nobrainer_streams.rb:68:in `run' | /opt/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/nobrainer_streams-0.2.0/lib/nobrainer_streams/rethinkdb_monkeypatch.rb:248:in `async_run' | /opt/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/nobrainer_streams-0.2.0/lib/nobrainer_streams.rb:42:in `nobrainer_stream_from'
2017-03-30T20:36:04+00:00 INFO: UnreadThreadsChannel#stream_channel_data
2017-03-30T20:36:04+00:00 INFO: ChatListChannel#stream_channel_data({"unread"=>false})
2017-03-30T20:36:04+00:00 INFO: UnreadThreadsChannel transmitting {:unread_count=>15}
2017-03-30T20:36:04+00:00 ERROR: Could not execute command from {"command"=>"message", "identifier"=>"{\"channel\":\"UnreadThreadsChannel\"}", "data"=>"{\"action\":\"stream_channel_data\"}"}) [RethinkDB::ReqlRuntimeError - Connection is closed.]: /opt/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/nobrainer_streams-0.2.0/lib/nobrainer_streams/rethinkdb_monkeypatch.rb:258:in `run' | /opt/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/nobrainer_streams-0.2.0/lib/nobrainer_streams/rethinkdb_monkeypatch.rb:249:in `block in async_run' | /opt/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/nobrainer_streams-0.2.0/lib/nobrainer_streams.rb:68:in `run' | /opt/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/nobrainer_streams-0.2.0/lib/nobrainer_streams/rethinkdb_monkeypatch.rb:248:in `async_run' | /opt/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/nobrainer_streams-0.2.0/lib/nobrainer_streams.rb:42:in `nobrainer_stream_from'
2017-03-30T20:36:04+00:00 ERROR: Could not execute command from {"command"=>"message", "identifier"=>"{\"channel\":\"ChatListChannel\"}", "data"=>"{\"unread\":false,\"action\":\"stream_channel_data\"}"}) [RethinkDB::ReqlRuntimeError - Connection is closed.]: /opt/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/nobrainer_streams-0.2.0/lib/nobrainer_streams/rethinkdb_monkeypatch.rb:258:in `run' | /opt/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/nobrainer_streams-0.2.0/lib/nobrainer_streams/rethinkdb_monkeypatch.rb:249:in `block in async_run' | /opt/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/nobrainer_streams-0.2.0/lib/nobrainer_streams.rb:68:in `run' | /opt/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/nobrainer_streams-0.2.0/lib/nobrainer_streams/rethinkdb_monkeypatch.rb:248:in `async_run' | /opt/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/nobrainer_streams-0.2.0/lib/nobrainer_streams.rb:42:in `nobrainer_stream_from'

The channel looks like this:

class ChatListChannel < ApplicationCable::Channel

  include NoBrainer::Streams

  def subscribed
    chats_list = message_threads_collection
                   .order_by(filtering_index: :desc)
                   .limit(LIST_LIMIT)
                   .with_index(:filtering_index)
    stream_from chats_list, { include_initial: true }, ->(change) { transmit_thread(change) }
  end

  def unsubscribed
    # Any cleanup needed when channel is unsubscribed
  end
  
end
@jeroenvisser101
Copy link
Contributor

You're using the code from #192 right? Maybe comment there, since it wasn't merged yet, it could be taken into account.

@as-gennadiy-n
Copy link
Author

Yep, thanks

@nviennot nviennot closed this as completed Apr 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants