ngauthier / tubesock

Websocket interface on Rack Hijack w/ Rails support
MIT License
620 stars 43 forks source link

Hijack method complains it is lacking local env variable #53

Closed xanguera closed 7 years ago

xanguera commented 7 years ago

Hi, I am trying to use the gem in Rails 5+ inside a controller. I have so far just added the example code and tried to connect, but I am getting the error below. I am a beginner in ruby/rails and don't know what to do (sorry if it is a generic/trivial question).

NameError - undefined local variable or method `env' for #<SpeechApiController:0x007fb45a56be70>:
  tubesock (0.2.7) lib/tubesock/hijack.rb:30:in `hijack'
  app/controllers/speech_api_controller.rb:14:in `websocket'
  actionpack (5.1.2) lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action'
  actionpack (5.1.2) lib/abstract_controller/base.rb:186:in `process_action'
  actionpack (5.1.2) lib/action_controller/metal/rendering.rb:30:in `process_action'
  actionpack (5.1.2) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
  activesupport (5.1.2) lib/active_support/callbacks.rb:131:in `run_callbacks'
  actionpack (5.1.2) lib/abstract_controller/callbacks.rb:19:in `process_action'
  actionpack (5.1.2) lib/action_controller/metal/rescue.rb:20:in `process_action'
  actionpack (5.1.2) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
  activesupport (5.1.2) lib/active_support/notifications.rb:166:in `block in instrument'
  activesupport (5.1.2) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
  activesupport (5.1.2) lib/active_support/notifications.rb:166:in `instrument'
  actionpack (5.1.2) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
  actionpack (5.1.2) lib/action_controller/metal/params_wrapper.rb:252:in `process_action'
  activerecord (5.1.2) lib/active_record/railties/controller_runtime.rb:22:in `process_action'
  actionpack (5.1.2) lib/abstract_controller/base.rb:124:in `process'
  actionview (5.1.2) lib/action_view/rendering.rb:30:in `process'
  actionpack (5.1.2) lib/action_controller/metal.rb:189:in `dispatch'
  actionpack (5.1.2) lib/action_controller/metal.rb:253:in `dispatch'
  actionpack (5.1.2) lib/action_dispatch/routing/route_set.rb:49:in `dispatch'
  actionpack (5.1.2) lib/action_dispatch/routing/route_set.rb:31:in `serve'
  actionpack (5.1.2) lib/action_dispatch/journey/router.rb:46:in `block in serve'
  actionpack (5.1.2) lib/action_dispatch/journey/router.rb:33:in `serve'
  actionpack (5.1.2) lib/action_dispatch/routing/route_set.rb:832:in `call'
  newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
  rack-pjax (1.0.0) lib/rack/pjax.rb:12:in `call'
  newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
  newrelic_rpm (4.3.0.335) lib/new_relic/rack/agent_hooks.rb:30:in `traced_call'
  newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
  newrelic_rpm (4.3.0.335) lib/new_relic/rack/browser_monitoring.rb:32:in `traced_call'
  newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
  app/middleware/exercise_backend.rb:575:in `call'
  newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
  remotipart (1.3.1) lib/remotipart/middleware.rb:32:in `call'
  newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
  warden (1.2.7) lib/warden/manager.rb:36:in `block in call'
  warden (1.2.7) lib/warden/manager.rb:35:in `call'
  newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
  rack (2.0.3) lib/rack/etag.rb:25:in `call'
  newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
  rack (2.0.3) lib/rack/conditional_get.rb:25:in `call'
  newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
  rack (2.0.3) lib/rack/head.rb:12:in `call'
  newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
  rack (2.0.3) lib/rack/session/abstract/id.rb:232:in `context'
  rack (2.0.3) lib/rack/session/abstract/id.rb:226:in `call'
  newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
  actionpack (5.1.2) lib/action_dispatch/middleware/cookies.rb:613:in `call'
  newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
  activerecord (5.1.2) lib/active_record/migration.rb:556:in `call'
  newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
  actionpack (5.1.2) lib/action_dispatch/middleware/callbacks.rb:26:in `block in call'
  activesupport (5.1.2) lib/active_support/callbacks.rb:97:in `run_callbacks'
  actionpack (5.1.2) lib/action_dispatch/middleware/callbacks.rb:24:in `call'
  newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
  actionpack (5.1.2) lib/action_dispatch/middleware/executor.rb:12:in `call'
  newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
  better_errors (2.3.0) lib/better_errors/middleware.rb:84:in `protected_app_call'
  better_errors (2.3.0) lib/better_errors/middleware.rb:79:in `better_errors_call'
  better_errors (2.3.0) lib/better_errors/middleware.rb:57:in `call'
  newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
  actionpack (5.1.2) lib/action_dispatch/middleware/debug_exceptions.rb:59:in `call'
  newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
  web-console (2.3.0) lib/web_console/middleware.rb:28:in `block in call'
  web-console (2.3.0) lib/web_console/middleware.rb:18:in `call'
  newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
  actionpack (5.1.2) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
  newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
  lograge (0.6.0) lib/lograge/rails_ext/rack/logger.rb:15:in `call_app'
  railties (5.1.2) lib/rails/rack/logger.rb:24:in `block in call'
  activesupport (5.1.2) lib/active_support/tagged_logging.rb:69:in `block in tagged'
  activesupport (5.1.2) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (5.1.2) lib/active_support/tagged_logging.rb:69:in `tagged'
  railties (5.1.2) lib/rails/rack/logger.rb:24:in `call'
  newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
  actionpack (5.1.2) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
  newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
  request_store (1.3.2) lib/request_store/middleware.rb:9:in `call'
  newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
  actionpack (5.1.2) lib/action_dispatch/middleware/request_id.rb:25:in `call'
  newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
  rack (2.0.3) lib/rack/method_override.rb:22:in `call'
  newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
  rack (2.0.3) lib/rack/runtime.rb:22:in `call'
  newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
  activesupport (5.1.2) lib/active_support/cache/strategy/local_cache_middleware.rb:27:in `call'
  newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
  actionpack (5.1.2) lib/action_dispatch/middleware/executor.rb:12:in `call'
  newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
  actionpack (5.1.2) lib/action_dispatch/middleware/static.rb:125:in `call'
  newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
  rack (2.0.3) lib/rack/sendfile.rb:111:in `call'
  newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
  railties (5.1.2) lib/rails/engine.rb:522:in `call'
  newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
  puma (3.9.1) lib/puma/configuration.rb:224:in `call'
  puma (3.9.1) lib/puma/server.rb:602:in `handle_request'
  puma (3.9.1) lib/puma/server.rb:435:in `process_client'
  puma (3.9.1) lib/puma/server.rb:299:in `block in run'
  puma (3.9.1) lib/puma/thread_pool.rb:120:in `block in spawn_thread'
ngauthier commented 7 years ago

Hey Xavier,

I'd recommend using ActionCable if you're on rails 5. Tubesock was more for Rails 4 before we had ActionCable.

Nick

On Aug 9, 2017 4:51 PM, "Xavier Anguera" notifications@github.com wrote:

Hi, I am trying to use the gem in Rails 5+ inside a controller. I have so far just added the example code and tried to connect, but I am getting the error below. I am a beginner in ruby/rails and don't know what to do (sorry if it is a generic/trivial question).

NameError - undefined local variable or method env' for #<SpeechApiController:0x007fb45a56be70>: tubesock (0.2.7) lib/tubesock/hijack.rb:30:inhijack' app/controllers/speech_api_controller.rb:14:in websocket' actionpack (5.1.2) lib/action_controller/metal/basic_implicit_render.rb:4:insend_action' actionpack (5.1.2) lib/abstract_controller/base.rb:186:in process_action' actionpack (5.1.2) lib/action_controller/metal/rendering.rb:30:inprocess_action' actionpack (5.1.2) lib/abstract_controller/callbacks.rb:20:in block in process_action' activesupport (5.1.2) lib/active_support/callbacks.rb:131:inrun_callbacks' actionpack (5.1.2) lib/abstract_controller/callbacks.rb:19:in process_action' actionpack (5.1.2) lib/action_controller/metal/rescue.rb:20:inprocess_action' actionpack (5.1.2) lib/action_controller/metal/instrumentation.rb:32:in block in process_action' activesupport (5.1.2) lib/active_support/notifications.rb:166:inblock in instrument' activesupport (5.1.2) lib/active_support/notifications/instrumenter.rb:21:in instrument' activesupport (5.1.2) lib/active_support/notifications.rb:166:ininstrument' actionpack (5.1.2) lib/action_controller/metal/instrumentation.rb:30:in process_action' actionpack (5.1.2) lib/action_controller/metal/params_wrapper.rb:252:inprocess_action' activerecord (5.1.2) lib/active_record/railties/controller_runtime.rb:22:in process_action' actionpack (5.1.2) lib/abstract_controller/base.rb:124:inprocess' actionview (5.1.2) lib/action_view/rendering.rb:30:in process' actionpack (5.1.2) lib/action_controller/metal.rb:189:indispatch' actionpack (5.1.2) lib/action_controller/metal.rb:253:in dispatch' actionpack (5.1.2) lib/action_dispatch/routing/route_set.rb:49:indispatch' actionpack (5.1.2) lib/action_dispatch/routing/route_set.rb:31:in serve' actionpack (5.1.2) lib/action_dispatch/journey/router.rb:46:inblock in serve' actionpack (5.1.2) lib/action_dispatch/journey/router.rb:33:in serve' actionpack (5.1.2) lib/action_dispatch/routing/route_set.rb:832:incall' newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call' rack-pjax (1.0.0) lib/rack/pjax.rb:12:incall' newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call' newrelic_rpm (4.3.0.335) lib/new_relic/rack/agent_hooks.rb:30:intraced_call' newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call' newrelic_rpm (4.3.0.335) lib/new_relic/rack/browser_monitoring.rb:32:intraced_call' newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call' app/middleware/exercise_backend.rb:575:incall' newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call' remotipart (1.3.1) lib/remotipart/middleware.rb:32:incall' newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call' warden (1.2.7) lib/warden/manager.rb:36:inblock in call' warden (1.2.7) lib/warden/manager.rb:35:in call' newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:incall' rack (2.0.3) lib/rack/etag.rb:25:in call' newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:incall' rack (2.0.3) lib/rack/conditional_get.rb:25:in call' newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:incall' rack (2.0.3) lib/rack/head.rb:12:in call' newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:incall' rack (2.0.3) lib/rack/session/abstract/id.rb:232:in context' rack (2.0.3) lib/rack/session/abstract/id.rb:226:incall' newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call' actionpack (5.1.2) lib/action_dispatch/middleware/cookies.rb:613:incall' newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call' activerecord (5.1.2) lib/active_record/migration.rb:556:incall' newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call' actionpack (5.1.2) lib/action_dispatch/middleware/callbacks.rb:26:inblock in call' activesupport (5.1.2) lib/active_support/callbacks.rb:97:in run_callbacks' actionpack (5.1.2) lib/action_dispatch/middleware/callbacks.rb:24:incall' newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call' actionpack (5.1.2) lib/action_dispatch/middleware/executor.rb:12:incall' newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call' better_errors (2.3.0) lib/better_errors/middleware.rb:84:inprotected_app_call' better_errors (2.3.0) lib/better_errors/middleware.rb:79:in better_errors_call' better_errors (2.3.0) lib/better_errors/middleware.rb:57:incall' newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call' actionpack (5.1.2) lib/action_dispatch/middleware/debug_exceptions.rb:59:incall' newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call' web-console (2.3.0) lib/web_console/middleware.rb:28:inblock in call' web-console (2.3.0) lib/web_console/middleware.rb:18:in call' newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:incall' actionpack (5.1.2) lib/action_dispatch/middleware/show_exceptions.rb:31:in call' newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:incall' lograge (0.6.0) lib/lograge/rails_ext/rack/logger.rb:15:in call_app' railties (5.1.2) lib/rails/rack/logger.rb:24:inblock in call' activesupport (5.1.2) lib/active_support/tagged_logging.rb:69:in block in tagged' activesupport (5.1.2) lib/active_support/tagged_logging.rb:26:intagged' activesupport (5.1.2) lib/active_support/tagged_logging.rb:69:in tagged' railties (5.1.2) lib/rails/rack/logger.rb:24:incall' newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call' actionpack (5.1.2) lib/action_dispatch/middleware/remote_ip.rb:79:incall' newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call' request_store (1.3.2) lib/request_store/middleware.rb:9:incall' newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call' actionpack (5.1.2) lib/action_dispatch/middleware/request_id.rb:25:incall' newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call' rack (2.0.3) lib/rack/method_override.rb:22:incall' newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call' rack (2.0.3) lib/rack/runtime.rb:22:incall' newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call' activesupport (5.1.2) lib/active_support/cache/strategy/local_cache_middleware.rb:27:incall' newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call' actionpack (5.1.2) lib/action_dispatch/middleware/executor.rb:12:incall' newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call' actionpack (5.1.2) lib/action_dispatch/middleware/static.rb:125:incall' newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call' rack (2.0.3) lib/rack/sendfile.rb:111:incall' newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call' railties (5.1.2) lib/rails/engine.rb:522:incall' newrelic_rpm (4.3.0.335) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call' puma (3.9.1) lib/puma/configuration.rb:224:incall' puma (3.9.1) lib/puma/server.rb:602:in handle_request' puma (3.9.1) lib/puma/server.rb:435:inprocess_client' puma (3.9.1) lib/puma/server.rb:299:in block in run' puma (3.9.1) lib/puma/thread_pool.rb:120:inblock in spawn_thread'

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ngauthier/tubesock/issues/53, or mute the thread https://github.com/notifications/unsubscribe-auth/AAA1Vg7SZfnFJl_e4cwe1YzGQWEAv9afks5sWhvOgaJpZM4Oyn58 .

xanguera commented 7 years ago

Hi nick, Thanks a lot for the recommendation. I had not looked into ActionCable as all posts I find are pre 2015. I will do right away. I am basically looking for a way to make my server serve both http and websocket requests. I have been experimenting with Faye-websocket, but I can only get a single thread per Puma process to serve requests. This is why I was not trying Tubesock. With your experience, would ActionCable solve my problem? any reference link you could propose?

Thanks!

ngauthier commented 7 years ago

Yes, I think it should work great for you. Here's the rails guide:

http://guides.rubyonrails.org/action_cable_overview.html

On Aug 9, 2017 5:19 PM, "Xavier Anguera" notifications@github.com wrote:

Hi nick, Thanks a lot for the recommendation. I had not looked into ActionCable as all posts I find are pre 2015. I will do right away. I am basically looking for a way to make my server serve both http and websocket requests. I have been experimenting with Faye-websocket, but I can only get a single thread per Puma process to serve requests. This is why I was not trying Tubesock. With your experience, would ActionCable solve my problem? any reference link you could propose?

Thanks!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ngauthier/tubesock/issues/53#issuecomment-321384500, or mute the thread https://github.com/notifications/unsubscribe-auth/AAA1Vv4lT9Iawxy8ypAS4Abi2Jt5yykQks5sWiJSgaJpZM4Oyn58 .

xanguera commented 7 years ago

Thanks a lot!

ngauthier commented 7 years ago

Np