websocket-rails / websocket-rails

Plug and play websocket support for ruby on rails.
MIT License
1.73k stars 284 forks source link

FiberError - can't yield from root fibe #191

Closed selivandex closed 10 years ago

selivandex commented 10 years ago

I trying to trigger some event In standalone mode and getting error

This is full stack

FiberError - can't yield from root fiber:
   () Users/selivandex/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/em-synchrony-ad17ce925fe4/lib/em-synchrony.rb:75:in `sync'
  redis (3.0.7) lib/redis/connection/synchrony.rb:47:in `read'
  redis (3.0.7) lib/redis/connection/synchrony.rb:110:in `read'
  redis (3.0.7) lib/redis/client.rb:229:in `block in read'
  redis (3.0.7) lib/redis/client.rb:220:in `io'
  redis (3.0.7) lib/redis/client.rb:228:in `read'
  redis (3.0.7) lib/redis/client.rb:96:in `block in call'
  redis (3.0.7) lib/redis/client.rb:201:in `block (2 levels) in process'
  redis (3.0.7) lib/redis/client.rb:309:in `ensure_connected'
  redis (3.0.7) lib/redis/client.rb:191:in `block in process'
  redis (3.0.7) lib/redis/client.rb:270:in `logging'
  redis (3.0.7) lib/redis/client.rb:190:in `process'
  redis (3.0.7) lib/redis/client.rb:96:in `call'
  redis (3.0.7) lib/redis.rb:1821:in `block in hget'
  redis (3.0.7) lib/redis.rb:37:in `block in synchronize'
  /Users/selivandex/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
  redis (3.0.7) lib/redis.rb:37:in `synchronize'
  redis (3.0.7) lib/redis.rb:1820:in `hget'
  redis-objects (0.9.0) lib/redis/hash_key.rb:27:in `hget'
   () Users/selivandex/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/websocket-rails-060af4602a05/lib/websocket_rails/channel.rb:58:in `token'
   () Users/selivandex/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/websocket-rails-060af4602a05/lib/websocket_rails/channel.rb:31:in `trigger'
  app/views/api/v1/sympathies/create.json.jbuilder:7:in `_app_views_api_v__sympathies_create_json_jbuilder__4268387822506745492_70181429715020'
  actionpack (4.0.2) lib/action_view/template.rb:143:in `block in render'
  activesupport (4.0.2) lib/active_support/notifications.rb:161:in `instrument'
  actionpack (4.0.2) lib/action_view/template.rb:141:in `render'
  actionpack (4.0.2) lib/action_view/renderer/template_renderer.rb:49:in `block (2 levels) in render_template'
  actionpack (4.0.2) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
  activesupport (4.0.2) lib/active_support/notifications.rb:159:in `block in instrument'
  activesupport (4.0.2) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (4.0.2) lib/active_support/notifications.rb:159:in `instrument'
  actionpack (4.0.2) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
  actionpack (4.0.2) lib/action_view/renderer/template_renderer.rb:48:in `block in render_template'
  actionpack (4.0.2) lib/action_view/renderer/template_renderer.rb:56:in `render_with_layout'
  actionpack (4.0.2) lib/action_view/renderer/template_renderer.rb:47:in `render_template'
  actionpack (4.0.2) lib/action_view/renderer/template_renderer.rb:17:in `render'
  actionpack (4.0.2) lib/action_view/renderer/renderer.rb:42:in `render_template'
  actionpack (4.0.2) lib/action_view/renderer/renderer.rb:23:in `render'
  actionpack (4.0.2) lib/abstract_controller/rendering.rb:127:in `_render_template'
  actionpack (4.0.2) lib/action_controller/metal/streaming.rb:219:in `_render_template'
  actionpack (4.0.2) lib/abstract_controller/rendering.rb:120:in `render_to_body'
  actionpack (4.0.2) lib/action_controller/metal/rendering.rb:33:in `render_to_body'
  actionpack (4.0.2) lib/action_controller/metal/renderers.rb:26:in `render_to_body'
  actionpack (4.0.2) lib/abstract_controller/rendering.rb:97:in `render'
  actionpack (4.0.2) lib/action_controller/metal/rendering.rb:16:in `render'
  actionpack (4.0.2) lib/action_controller/metal/instrumentation.rb:41:in `block (2 levels) in render'
  activesupport (4.0.2) lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
  /Users/selivandex/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/benchmark.rb:296:in `realtime'
  activesupport (4.0.2) lib/active_support/core_ext/benchmark.rb:12:in `ms'
  actionpack (4.0.2) lib/action_controller/metal/instrumentation.rb:41:in `block in render'
  actionpack (4.0.2) lib/action_controller/metal/instrumentation.rb:84:in `cleanup_view_runtime'
  actionpack (4.0.2) lib/action_controller/metal/instrumentation.rb:40:in `render'
  remotipart (1.2.1) lib/remotipart/render_overrides.rb:14:in `render_with_remotipart'
  actionpack (4.0.2) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
  actionpack (4.0.2) lib/action_controller/metal/implicit_render.rb:5:in `send_action'
  actionpack (4.0.2) lib/abstract_controller/base.rb:189:in `process_action'
  actionpack (4.0.2) lib/action_controller/metal/rendering.rb:10:in `process_action'
  actionpack (4.0.2) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
  activesupport (4.0.2) lib/active_support/callbacks.rb:443:in `_run__3619126610137267988__process_action__callbacks'
  activesupport (4.0.2) lib/active_support/callbacks.rb:80:in `run_callbacks'
  actionpack (4.0.2) lib/abstract_controller/callbacks.rb:17:in `process_action'
  actionpack (4.0.2) lib/action_controller/metal/rescue.rb:29:in `process_action'
  actionpack (4.0.2) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
  activesupport (4.0.2) lib/active_support/notifications.rb:159:in `block in instrument'
  activesupport (4.0.2) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (4.0.2) lib/active_support/notifications.rb:159:in `instrument'
  actionpack (4.0.2) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
  actionpack (4.0.2) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
  actionpack (4.0.2) lib/abstract_controller/base.rb:136:in `process'
  actionpack (4.0.2) lib/abstract_controller/rendering.rb:44:in `process'
  actionpack (4.0.2) lib/action_controller/metal.rb:195:in `dispatch'
  actionpack (4.0.2) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
  actionpack (4.0.2) lib/action_controller/metal.rb:231:in `block in action'
  actionpack (4.0.2) lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
  actionpack (4.0.2) lib/action_dispatch/routing/route_set.rb:48:in `call'
  actionpack (4.0.2) lib/action_dispatch/journey/router.rb:71:in `block in call'
  actionpack (4.0.2) lib/action_dispatch/journey/router.rb:59:in `call'
  actionpack (4.0.2) lib/action_dispatch/routing/route_set.rb:680:in `call'
  rack-pjax (0.7.0) lib/rack/pjax.rb:12:in `call'
  meta_request (0.2.8) lib/meta_request/middlewares/app_request_handler.rb:13:in `call'
  rack-contrib (1.1.0) lib/rack/contrib/response_headers.rb:17:in `call'
  meta_request (0.2.8) lib/meta_request/middlewares/headers.rb:16:in `call'
  meta_request (0.2.8) lib/meta_request/middlewares/meta_request_handler.rb:13:in `call'
  warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
  warden (1.2.3) lib/warden/manager.rb:34:in `call'
  rack (1.5.2) lib/rack/etag.rb:23:in `call'
  rack (1.5.2) lib/rack/conditionalget.rb:25:in `call'
  rack (1.5.2) lib/rack/head.rb:11:in `call'
  remotipart (1.2.1) lib/remotipart/middleware.rb:27:in `call'
  actionpack (4.0.2) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
  actionpack (4.0.2) lib/action_dispatch/middleware/flash.rb:241:in `call'
  rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
  rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
  actionpack (4.0.2) lib/action_dispatch/middleware/cookies.rb:486:in `call'
  actionpack (4.0.2) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
  activesupport (4.0.2) lib/active_support/callbacks.rb:373:in `_run__4258674676079134758__call__callbacks'
  activesupport (4.0.2) lib/active_support/callbacks.rb:80:in `run_callbacks'
  actionpack (4.0.2) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (4.0.2) lib/action_dispatch/middleware/reloader.rb:64:in `call'
  actionpack (4.0.2) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
  better_errors (1.1.0) lib/better_errors/middleware.rb:84:in `protected_app_call'
  better_errors (1.1.0) lib/better_errors/middleware.rb:79:in `better_errors_call'
  better_errors (1.1.0) lib/better_errors/middleware.rb:56:in `call'
  actionpack (4.0.2) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
  actionpack (4.0.2) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.0.2) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.0.2) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.0.2) lib/active_support/tagged_logging.rb:67:in `block in tagged'
  activesupport (4.0.2) lib/active_support/tagged_logging.rb:25:in `tagged'
  activesupport (4.0.2) lib/active_support/tagged_logging.rb:67:in `tagged'
  railties (4.0.2) lib/rails/rack/logger.rb:20:in `call'
  actionpack (4.0.2) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
  rack-contrib (1.1.0) lib/rack/contrib/runtime.rb:18:in `call'
  activesupport (4.0.2) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
  actionpack (4.0.2) lib/action_dispatch/middleware/static.rb:64:in `call'
  rack-contrib (1.1.0) lib/rack/contrib/sendfile.rb:105:in `call'
  railties (4.0.2) lib/rails/engine.rb:511:in `call'
  railties (4.0.2) lib/rails/application.rb:97:in `call'
  rack (1.5.2) lib/rack/content_length.rb:14:in `call'
  thin (1.6.2) lib/thin/connection.rb:86:in `block in pre_process'
  thin (1.6.2) lib/thin/connection.rb:84:in `pre_process'
  thin (1.6.2) lib/thin/connection.rb:53:in `process'
  faye-websocket (0.7.2) lib/faye/adapters/thin.rb:40:in `process'
  thin (1.6.2) lib/thin/connection.rb:39:in `receive_data'
  faye-websocket (0.7.2) lib/faye/adapters/thin.rb:44:in `receive_data'
  eventmachine (1.0.3) lib/eventmachine.rb:187:in `run'
  thin (1.6.2) lib/thin/backends/base.rb:73:in `start'
  thin (1.6.2) lib/thin/server.rb:162:in `start'
  rack (1.5.2) lib/rack/handler/thin.rb:16:in `run'
  rack (1.5.2) lib/rack/server.rb:264:in `start'
  railties (4.0.2) lib/rails/commands/server.rb:84:in `start'
  railties (4.0.2) lib/rails/commands.rb:76:in `block in <top (required)>'
  railties (4.0.2) lib/rails/commands.rb:71:in `<top (required)>'
  bin/rails:4:in `<main>'

Exiting
/Users/selivandex/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/em-synchrony-ad17ce925fe4/lib/em-synchrony.rb:66:in `block in sync': unexpected return (LocalJumpError)
  from /Users/selivandex/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/eventmachine-1.0.3/lib/em/deferrable.rb:158:in `call'
  from /Users/selivandex/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/eventmachine-1.0.3/lib/em/deferrable.rb:158:in `set_deferred_status'
  from /Users/selivandex/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/eventmachine-1.0.3/lib/em/deferrable.rb:198:in `fail'
  from /Users/selivandex/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/redis-3.0.7/lib/redis/connection/synchrony.rb:57:in `unbind'
  from /Users/selivandex/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/eventmachine-1.0.3/lib/eventmachine.rb:1440:in `event_callback'
  from /Users/selivandex/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/eventmachine-1.0.3/lib/eventmachine.rb:187:in `run_machine'
  from /Users/selivandex/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/eventmachine-1.0.3/lib/eventmachine.rb:187:in `run'
  from /Users/selivandex/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/thin-1.6.2/lib/thin/backends/base.rb:73:in `start'
  from /Users/selivandex/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/thin-1.6.2/lib/thin/server.rb:162:in `start'
  from /Users/selivandex/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/handler/thin.rb:16:in `run'
  from /Users/selivandex/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/server.rb:264:in `start'
  from /Users/selivandex/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.2/lib/rails/commands/server.rb:84:in `start'
  from /Users/selivandex/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.2/lib/rails/commands.rb:76:in `block in <top (required)>'
  from /Users/selivandex/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.2/lib/rails/commands.rb:71:in `tap'
  from /Users/selivandex/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.2/lib/rails/commands.rb:71:in `<top (required)>'
  from bin/rails:4:in `require'
  from bin/rails:4:in `<main>'

Somebody knows what i doing wrong?

KazW commented 10 years ago
Fiber.new{ your_call }.resume

This can fix a lot of issues, but your mileage may vary.

DanKnox commented 10 years ago

@KazW's solution should fix your problem if EventMachine is running. The cause of the problem has to do with the EM::Synchrony Redis driver.

If you are running this from a background process that does not have EventMachine running you can work around this by changing the redis driver that WebsocketRails uses.

In the initialization of that process you could add the following code:

WebsocketRails.setup do |config|
  config.redis_options = {driver: :ruby}
end

You can also add any of the other available Redis options to that hash as it's passed directly to the Redis client.

guoyk93 commented 10 years ago

Well, my problem is the whole rails application will be stucked and can only be killed by SIGKILL after booted up, if i specified a redis driver, such as hiredis or ruby.

JeanMertz commented 10 years ago

I too ran into this issue (while using Sidekiq). Using the ruby driver did also lock my processes like @yanke-guo, and since Sidekiq doesn't use EventMachine, I guess using new { ... }.resume is not an option.

Any other ideas?

TrevTheDev commented 10 years ago

+1 for me

DougPuchalski commented 10 years ago

+1

DougPuchalski commented 10 years ago

Why is this closed? Sounds like the workaround is not applicable to the original report.

JeanMertz commented 10 years ago

@aceofspades Fiber.new{ your_call }.resume did solve it for me by the way.

See https://github.com/kabisaict/flow/commit/811d5de8e22aec254270a467a60b4d19e25dfdd5 for an example.

DougPuchalski commented 10 years ago

Thanks for the link @JeanMertz

Tectract commented 9 years ago

+1

Is there some workaround here that doesn't involve forking this repo? All I could find to fix my server crash

synchrony.rb:78:in `resume': double resume (FiberError)

was here:

https://github.com/Bivek/websocket-rails/commit/208e7521f2be4e56f284472a6a07b740f3052537

[edit]
ok, hmmmm adding

config.redis_options = {driver: :ruby}

into config/websocket_rails.rb did not fix the problem, argh. I actually had to go into lib/websocket_rails/synchronization.rb and comment out the synchrony include line to even get my rails server to serve a single page with this gem installed. I'd say "critical bug".