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

ArgumentError (wrong number of arguments (given 2, expected 1)) #22

Closed
sandy1987 opened this issue Nov 21, 2017 · 36 comments
Closed

ArgumentError (wrong number of arguments (given 2, expected 1)) #22

sandy1987 opened this issue Nov 21, 2017 · 36 comments

Comments

@sandy1987
Copy link

Hello,

Please let me know the solution, So I will update the code as well
I have follow this links
https://github.com/anycable/anycable-rails

ArgumentError (wrong number of arguments (given 2, expected 1)):

anycable-rails (0.5.0) lib/anycable/rails/actioncable/connection.rb:29:in initialize' actioncable (5.0.6) lib/action_cable/server/base.rb:28:in new'
actioncable (5.0.6) lib/action_cable/server/base.rb:28:in call' actionpack (5.0.6) lib/action_dispatch/routing/mapper.rb:17:in block in class:Constraints'
actionpack (5.0.6) lib/action_dispatch/routing/mapper.rb:46:in serve' actionpack (5.0.6) lib/action_dispatch/journey/router.rb:39:in block in serve'
actionpack (5.0.6) lib/action_dispatch/journey/router.rb:26:in each' actionpack (5.0.6) lib/action_dispatch/journey/router.rb:26:in serve'
actionpack (5.0.6) lib/action_dispatch/routing/route_set.rb:727: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 catch' warden (1.2.7) lib/warden/manager.rb:35:in call'
rack (2.0.3) lib/rack/etag.rb:25:in call' rack (2.0.3) lib/rack/conditional_get.rb:25:in call'
rack (2.0.3) lib/rack/head.rb:12: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' actionpack (5.0.6) lib/action_dispatch/middleware/cookies.rb:613:in call'
activerecord (5.0.6) lib/active_record/migration.rb:553:in call' actionpack (5.0.6) lib/action_dispatch/middleware/callbacks.rb:38:in block in call'
activesupport (5.0.6) lib/active_support/callbacks.rb:97:in __run_callbacks__' activesupport (5.0.6) lib/active_support/callbacks.rb:750:in _run_call_callbacks'
activesupport (5.0.6) lib/active_support/callbacks.rb:90:in run_callbacks' actionpack (5.0.6) lib/action_dispatch/middleware/callbacks.rb:36:in call'
actionpack (5.0.6) lib/action_dispatch/middleware/executor.rb:12:in call' actionpack (5.0.6) lib/action_dispatch/middleware/remote_ip.rb:79:in call'
actionpack (5.0.6) lib/action_dispatch/middleware/debug_exceptions.rb:49:in call' web-console (3.5.1) lib/web_console/middleware.rb:135:in call_app'
web-console (3.5.1) lib/web_console/middleware.rb:28:in block in call' web-console (3.5.1) lib/web_console/middleware.rb:18:in catch'
web-console (3.5.1) lib/web_console/middleware.rb:18:in call' actionpack (5.0.6) lib/action_dispatch/middleware/show_exceptions.rb:31:in call'
railties (5.0.6) lib/rails/rack/logger.rb:36:in call_app' railties (5.0.6) lib/rails/rack/logger.rb:24:in block in call'
activesupport (5.0.6) lib/active_support/tagged_logging.rb:69:in block in tagged' activesupport (5.0.6) lib/active_support/tagged_logging.rb:26:in tagged'
activesupport (5.0.6) lib/active_support/tagged_logging.rb:69:in tagged' railties (5.0.6) lib/rails/rack/logger.rb:24:in call'
sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in call' actionpack (5.0.6) lib/action_dispatch/middleware/request_id.rb:24:in call'
rack (2.0.3) lib/rack/method_override.rb:22:in call' rack (2.0.3) lib/rack/runtime.rb:22:in call'
activesupport (5.0.6) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in call' actionpack (5.0.6) lib/action_dispatch/middleware/executor.rb:12:in call'
actionpack (5.0.6) lib/action_dispatch/middleware/static.rb:136:in call' rack (2.0.3) lib/rack/sendfile.rb:111:in call'
railties (5.0.6) lib/rails/engine.rb:522:in call' puma (3.11.0) lib/puma/configuration.rb:225:in call'
puma (3.11.0) lib/puma/server.rb:624:in handle_request' puma (3.11.0) lib/puma/server.rb:438:in process_client'
puma (3.11.0) lib/puma/server.rb:302:in block in run' puma (3.11.0) lib/puma/thread_pool.rb:120:in block in spawn_thread'
Rendering /home/yuva/.rvm/gems/ruby-2.3.0/gems/actionpack-5.0.6/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout
Rendering /home/yuva/.rvm/gems/ruby-2.3.0/gems/actionpack-5.0.6/lib/action_dispatch/middleware/templates/rescues/_source.html.erb
Rendered /home/yuva/.rvm/gems/ruby-2.3.0/gems/actionpack-5.0.6/lib/action_dispatch/middleware/templates/rescues/_source.html.erb (3.1ms)
Rendering /home/yuva/.rvm/gems/ruby-2.3.0/gems/actionpack-5.0.6/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb
Rendered /home/yuva/.rvm/gems/ruby-2.3.0/gems/actionpack-5.0.6/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (2.3ms)
Rendering /home/yuva/.rvm/gems/ruby-2.3.0/gems/actionpack-5.0.6/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb
Rendered /home/yuva/.rvm/gems/ruby-2.3.0/gems/actionpack-5.0.6/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.3ms)
Rendered /home/yuva/.rvm/gems/ruby-2.3.0/gems/actionpack-5.0.6/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (23.3ms)

@dmcclory
Copy link

I also hit this today! I followed the steps in the anycable-rails README and encountered a very similar similar stacktrace when I ran it on these 2 combinations of versions:

  • anycable (0.4.6), anycable-rails (0.4.7), and rails (5.1.0.rc1)
  • anycable (0.5.0), anycable-rails (0.5.0), and rails (5.1.0.rc1)

It might just be that the README is a little out of date? I'm going to keep poking around.

@palkan
Copy link
Member

palkan commented Nov 22, 2017

The problem is that you're trying to connect to Action Cable server and not to AnyCable (this line form backtrace lib/action_cable/server/base.rb:28:in new').

You should set up config.action_cable.url = "<URL for anycable-go application>" in your application.rb to make sure that JS client connects to the correct server.

Looks like your Action Cable server is mounted to your Rack stack. Do you have config.action_cable.mount_path = '/whatever' set in your configuration?

Also, how do you require anycable-rails (or how your Gemfile looks like)?

@sandy1987
Copy link
Author

Hello @palkan ,

Please let me know one things can we run application on different heroku server and we will use this url of that server

config.action_cable.url = ""
"" In place of this

@palkan
Copy link
Member

palkan commented Nov 22, 2017

can we run application on different heroku server and we will use this url of that server

If I understand your question correctly (I'm not sure), then – yes, you should use the url of the second server (running RPC and anycable-go) as action_cable.url.

@Crashtor
Copy link

Crashtor commented Nov 23, 2017

@palkan I get this error message as well. Your solution won't work for me, still getting the exact same error as @sandy1987. Fantastic work on anycable none the less. Can't wait to get it up and running. Actioncable truly is inefficiently designed.

@palkan
Copy link
Member

palkan commented Nov 23, 2017

There is definitely something with configuration but it's not easy to figure our what exactly without having an access to the codebase. So, if it's possible, please, share your code with me. Otherwise let's try other ways.

For example, it could be useful to see what's going on. Could you record a video demonstrating the problem? With server and browser network logs.

Logs also could be useful: turn on debug mode (in Rails config.log_level = :debug, for anycable-go – anycable-go -log). And send these logs to me.

@CR4567
Copy link

CR4567 commented Nov 23, 2017

Hey guys,
I was also working on the same problem for the last days. And like @palkan already mentioned, it was a problem of the configuration. The clients were always trying to connect to the "old" actioncable and to localhost instead of the correct path. So when I changed to
App.cable = ActionCable.createConsumer("ws://URL:PORT");
clients connected to the correct server and using
sudo ./anycable-go-0.5.1-linux-amd64 -addr='URL:PORT'
for the server, problem was solved.

Maybe this helps you too.

@CR4567
Copy link

CR4567 commented Nov 24, 2017

hm... it seems that I was wrong... the error still occurs and I get a handshake error even with setting
config.action_cable.allowed_request_origins = [/http:\/\/*/, /https:\/\/*/]
what seems to be the typical reason.
I will try to investigate further but also open for new ideas :-D

@palkan
Copy link
Member

palkan commented Nov 24, 2017

@CR4567 Hm, when using AnyCable allowed_request_origins is not used.

App.cable = ActionCable.createConsumer("ws://URL:PORT");

The path is missing as I see, should be: "ws://URL:PORT/cable"

@CR4567
Copy link

CR4567 commented Nov 24, 2017

@palkan ah thanks for the info...
so i can comment all the lines about the request origins...
but I already added the missing /cable to the path without any change....
my browser inspector gives me following error:
VM1864:164 WebSocket connection to 'ws://testing.easierlife.de:3334/' failed: Error during WebSocket handshake: Unexpected response code: 404
and stacktrace:
WrappedWebSocket @ VM1864:164 ActionCable.Connection.Connection.open @ intern-6b02134866f9eaf3198fff1bd45d69cd7c737c1a7e5f25b9bf0fd48e2b8f726d.js:28747 (anonymous) @ intern-6b02134866f9eaf3198fff1bd45d69cd7c737c1a7e5f25b9bf0fd48e2b8f726d.js:28711 ActionCable.Consumer.Consumer.ensureActiveConnection @ intern-6b02134866f9eaf3198fff1bd45d69cd7c737c1a7e5f25b9bf0fd48e2b8f726d.js:29091 ActionCable.Subscriptions.Subscriptions.add @ intern-6b02134866f9eaf3198fff1bd45d69cd7c737c1a7e5f25b9bf0fd48e2b8f726d.js:28908 ActionCable.Subscriptions.Subscriptions.create @ intern-6b02134866f9eaf3198fff1bd45d69cd7c737c1a7e5f25b9bf0fd48e2b8f726d.js:28903 App.Channels.InternEvent.subscribe @ intern-6b02134866f9eaf3198fff1bd45d69cd7c737c1a7e5f25b9bf0fd48e2b8f726d.js:29192 (anonymous) @ intern-6b02134866f9eaf3198fff1bd45d69cd7c737c1a7e5f25b9bf0fd48e2b8f726d.js:29637
I'm sure it's just a config problem but right now it feels like I tried most of the options :-(
Could it be a problem with nginx?
I'm just wondering because it worked before with actioncable

@palkan
Copy link
Member

palkan commented Nov 24, 2017

WebSocket connection to 'ws://testing.easierlife.de:3334/' failed:

Hm, there should be ws://testing.easierlife.de:3334/cable then.
Try to run the following in your browser console:

new WebSocket('ws://testing.easierlife.de:3334/cable')

@CR4567
Copy link

CR4567 commented Nov 24, 2017

oh boy... that was kind of stupid...
yeah I was also wondering why it still connects to the wrong url.
So the main problem was that I forgot to precompile the assets and still was on the old version... the reason why the url didn't changed... after precompiling now finally everything is running perfectly fine.... thanks a lot for you patience :-D

@Crashtor
Copy link

Crashtor commented Nov 25, 2017

@palkan I decided to redo the entire Heroku tutorial to the teeth, and while it seem to be connecting, I get a strange error when I try to send a chat message,

[NoMethodError - undefined method []' for false:FalseClass]:

/app/vendor/bundle/ruby/2.3.0/gems/anyway_config-0.4.0/lib/anyway/rails/config.rb:13:in load_from_file' | /app/vendor/bundle/ruby/2.3.0/gems/anyway_config-0.4.0/lib/anyway/rails/config.rb:4:in load_from_sources' | /app/vendor/bundle/ruby/2.3.0/gems/anyway_config-0.4.0/lib/anyway/config.rb:52:in load' | /app/vendor/bundle/ruby/2.3.0/gems/anyway_config-0.4.0/lib/anyway/config.rb:35:in initialize' | /app/vendor/bundle/ruby/2.3.0/gems/anycable-0.3.0/lib/anycable.rb:23:in new'`

UPDATE
Hmm, I just took a print screen of the browser debugger, and while it seem to be connecting to the /cable of the main-url, I get a handshake error on the RPC url.

print

UPDATE 2

I realized I had set the wrong gem in the gem file, now it's set as:

gem 'anycable-rails', group: :production

Printing ENV['CABLE_URL'] in console returns nil– But when setting it as a config variable in Heroku it returned the correct address of my attached RPC app.

=>
"wss://myapp-rpc.herokuapp.com/cable"

But somehow it does not pick it up from the Procfile.

Now I'm back to the exact same argument error as this post was originally created in the name of and I must stress that I have no problems with ActionCable in development.

UPDATE 3

I can see now on startup that it is actually picking up the anycable-go URL. But yes, it is indeed stil trying to mount the connection on the main-app URL as seen here:

at=info method=GET path="/cable" host=mainapp.herokuapp.com

Somewhere it's not kosher... I'm going through the code in your demo as I write this, so I will be sure to post more updates.

A question would be if it's required to use Docker or foreman?

UPDATE 4
My gemfile:
gem 'anycable-rails', group: :production

Procfile:
web: ANYCABLE_REDIS_URL=$REDIS_URL REDIS=$REDIS_URL ADDR="0.0.0.0:$PORT" CABLE_URL='wss://app-rpc.herokuapp.com/cable' bin/heroku-web

bin/heroku-web

if [ "$ANYCABLE_DEPLOYMENT" == "true" ]; then
  bundle exec ./bin/anycable
else
  bundle exec rails server -p $PORT -b 0.0.0.0  
fi

bin/anycable

require ::File.expand_path('../../config/environment', __FILE__)
require "anycable-rails"

Anycable.connection_factory = ActionCable.server.config.connection_class.call

Rails.application.eager_load!

if ENV['ANYCABLE_DEPLOYMENT']
  go_thread = Thread.new do
    Process.wait Process.spawn('anycable-go')
    raise "Anycable-Go failed!"
  end

  go_thread.abort_on_exception = true
end

Anycable::Server.start

production.rb ( I have tried setting this in application.rb too without any difference)

    config.action_cable.mount_path = nil
    config.action_cable.url = ENV['CABLE_URL']

Should I store the ENV as a variable in heroku or does it read the CABLE_URL from procfile? – I can see the following on in the logs when starting up the main process on heroku:

Starting process with commandANYCABLE_REDIS_URL=redis://h:pb85411ac3120d265445ff790c6dc45bb651ae77187cee54480afcee39a7905bd@ec2-34-252-202-201.eu-west-1.compute.amazonaws.com:27939 REDIS=redis://h:pb85411ac3120d265445ff790c6dc45bb651ae77187cee54480afcee39a7905bd@ec2-34-252-202-201.eu-west-1.compute.amazonaws.com:27939 ADDR="0.0.0.0:17199" CABLE_URL='wss://app-rpc.herokuapp.com/cable' bin/heroku-web

But then right after:

2017-11-25T11:34:09.874504+00:00 app[web.1]: => Booting Puma
2017-11-25T11:34:09.874507+00:00 app[web.1]: => Rails 5.0.6 application starting in production on http://0.0.0.0:17199
2017-11-25T11:34:09.874507+00:00 app[web.1]: => Run `rails server -h` for more startup options
2017-11-25T11:34:09.874509+00:00 app[web.1]: Puma starting in single mode...
2017-11-25T11:34:09.874513+00:00 app[web.1]: * Version 3.11.0 (ruby 2.3.4-p301), codename: Love Song
2017-11-25T11:34:09.874514+00:00 app[web.1]: * Min threads: 5, max threads: 5
2017-11-25T11:34:09.874516+00:00 app[web.1]: * Environment: production
2017-11-25T11:34:09.874630+00:00 app[web.1]: * Listening on tcp://0.0.0.0:17199
2017-11-25T11:34:09.874993+00:00 app[web.1]: Use Ctrl-C to stop
2017-11-25T11:34:13.283759+00:00 heroku[router]: at=info method=GET path="/cable" host=mainapp.herokuapp.com request_id=3b45b748-65bd-47ef-bf9b-cef74208b672 fwd="80.216.213.189" dyno=web.1 connect=0ms service=28ms status=500 bytes=1650 protocol=https
2017-11-25T11:34:13.256391+00:00 app[web.1]: [3b45b748-65bd-47ef-bf9b-cef74208b672] Started GET "/cable" for 80.216.213.189 at 2017-11-25 11:34:13 +0000

Routes.rb

mount ActionCable.server => '/cable'

cable.js

(function() {
  this.App || (this.App = {});
  console.log("consumer created cable.js")
  App.cable = ActionCable.createConsumer();

}).call(this);

Somehow, it simply does not want to connect to the correct host
Have I got something completely wrong? I'm still being thrown the 2 for 1 argument error.

UPDATE 5
# I have made some progress, After running heroku run chmod +x ./bin/anycable --app mainapp
It seems it's now actually trying to connect to the Anycable-go URL in Procfile.

image

Which in the procfile is currently set as:
CABLE_URL='wss://app-rpc.herokuapp.com/cable'

However, it seems that this is somehow the wrong URL as I get a lot of weird errors in the Chrome console

VM496:164 WebSocket connection to 'ws://app-rpc.herokuapp.com/cable' failed: Error during WebSocket handshake: Unexpected response code: 502

VM496:164 Mixed Content: The page at 'https://mainapp.herokuapp.com/' was loaded over HTTPS, but attempted to connect to the insecure WebSocket endpoint 'ws://app-rpc.herokuapp.com/cable'. This endpoint should be available via WSS. Insecure access is deprecated.

VM496:164 Connecting to a non-secure WebSocket server from a secure origin is deprecated.

(As you can see I'm using wss in my Procfile and not ws)

I also get this in Chrome when visiting the main url of my app.

image

Am I specifying the wrong anycable-go url?

UPDATE 7
I did like @CR4567 and passed the anycable go url directly as an argument where App.cable is defined.

assets/javascripts/cable.js
App.cable = ActionCable.createConsumer("wss://app-rpc.herokuapp.com/cable");

This removes the unsafe script warnings, but I'm still getting the same error as @CR4567 did before he managed to solve it, namely;
VM5352:164 WebSocket connection to 'wss://app-rpc.herokuapp.com/cable' failed: Error during WebSocket handshake: Unexpected response code: 502

Whyyyyyy.....

@palkan
Copy link
Member

palkan commented Nov 26, 2017

@Crashtor Can you show me the logs for RPC app? Usually, 502 means that something went wrong with proxy (Heroku router?). There should be errors in the log.

mount ActionCable.server => '/cable'

You don't need this in your routes.rb (that explains the initial problem – connecting to the Rails Action Cable server).
Rails automatically mounts Action Cable if config.action_cable.mount_path is not nil.

@Crashtor
Copy link

Crashtor commented Nov 26, 2017

rpc log

2017-11-25T23:06:14.067927+00:00 heroku[router]: at=info code=H81 desc="Blank app" method=GET path="/cable" host=app-rpc.herokuapp.com request_id=c54cf39f-337a-4a5e-9be9-c4e438a75c9d fwd="80.216.213.189" dyno= connect= service= status=502 bytes= protocol=https

2017-11-25T23:06:21.578307+00:00 heroku[router]: at=info code=H81 desc="Blank app" method=GET path="/cable" host=app-rpc.herokuapp.com request_id=f86df7f8-eec1-4ce8-a17d-d603d74b04f1 fwd="80.216.213.189" dyno= connect= service= status=502 bytes= protocol=https
2017-11-25T23:06:31.606320+00:00 heroku[router]: at=info code=H81 desc="Blank app" method=GET path="/cable" host=app-rpc.herokuapp.com request_id=0ae91cac-9c21-46c7-b821-3ee78f7e62a3 fwd="80.216.213.189" dyno= connect= service= status=502 bytes= protocol=https

2017-11-25T23:06:43.219509+00:00 heroku[router]: at=info code=H81 desc="Blank app" method=GET path="/cable" host=app-rpc.herokuapp.com request_id=8d5b13f1-5937-4ca2-82c8-0ef3fdf68061 fwd="80.216.213.189" dyno= connect= service= status=502 bytes= protocol=https
2017-11-25T23:06:50.995838+00:00 heroku[router]: at=info code=H81 desc="Blank app" method=GET path="/cable" host=app-rpc.herokuapp.com request_id=72924211-c37c-4c9d-866f-d4dcf6eeff04 fwd="80.216.213.189" dyno= connect= service= status=502 bytes= protocol=https
2017-11-25T23:07:01.590399+00:00 heroku[router]: at=info code=H81 desc="Blank app" method=GET path="/cable" host=app-rpc.herokuapp.com request_id=04316066-ce13-4520-97cd-e5da133eb3f8 fwd="80.216.213.189" dyno= connect= service= status=502 bytes= protocol=https
2017-11-25T23:07:14.487926+00:00 heroku[router]: at=info code=H81 desc="Blank app" method=GET path="/cable" host=app-rpc.herokuapp.com request_id=d9fdeef6-96b1-4292-b297-143c629b9887 fwd="80.216.213.189" dyno= connect= service= status=502 bytes= protocol=https
2017-11-25T23:07:27.880480+00:00 heroku[router]: at=info code=H81 desc="Blank app" method=GET path="/cable" host=app-rpc.herokuapp.com request_id=cecbae8f-2b9c-40b7-9d5d-c9f6b63b6497 fwd="80.216.213.189" dyno= connect= service= status=502 bytes= protocol=https
2017-11-25T23:07:40.530991+00:00 heroku[router]: at=info code=H81 desc="Blank app" method=GET path="/cable" host=app-rpc.herokuapp.com request_id=a561fcee-9d86-4798-9a3b-ee882d2e3d59 fwd="80.216.213.189" dyno= connect= service= status=502 bytes= protocol=https
2017-11-25T23:07:53.982357+00:00 heroku[router]: at=info code=H81 desc="Blank app" method=GET path="/cable" host=app-rpc.herokuapp.com request_id=79cc2652-9ba4-4a75-bdfd-95159b28df6a fwd="80.216.213.189" dyno= connect= service= status=502 bytes= protocol=https
2017-11-25T23:08:10.092004+00:00 heroku[router]: at=info code=H81 desc="Blank app" method=GET path="/cable" host=app-rpc.herokuapp.com request_id=d2dd74b2-e255-4227-b6e4-8e4dc2cf6bb9 fwd="80.216.213.189" dyno= connect= service= status=502 bytes= protocol=https

This is the anycable-go -log
Running AnyCable websocket server v0.5.0.1 on localhost:8080 at /cable
Ping interval 3s
Disconnect rate 10ms
Subscribed to Redis channel: anycable

@palkan
Copy link
Member

palkan commented Nov 26, 2017

@Crashtor Hm, Heroku says that there is no applicant code (https://devcenter.heroku.com/articles/error-codes#h81-blank-app).

Maybe, you forgot to push your repo to the second, RPC, remote?

I've just noticed that this step is missing in the wiki. My bad( Updated.

@Crashtor
Copy link

Crashtor commented Nov 26, 2017

Ok yes, that was correct, I had not done that. Now I have however, and here are the logs from the rpc app:

2017-11-26T15:01:36.104484+00:00 heroku[web.1]: Starting process with command ANYCABLE_REDIS_URL=redis://h:pb85411ac3120d265445ff790c6dc45bb651ae77187cee54480afcee39a7905bd@ec2-34-252-202-201.eu-west-1.compute.amazonaws.com:27939 REDIS=redis://h:pb85411ac3120d265445ff790c6dc45bb651ae77187cee54480afcee39a7905bd@ec2-34-252-202-201.eu-west-1.compute.amazonaws.com:27939 ADDR="0.0.0.0:12110" CABLE_URL='wss://app-rpc.herokuapp.com/cable' bin/heroku-web
2017-11-26T15:01:44.244602+00:00 app[web.1]: bundler: failed to load command: ./bin/anycable (./bin/anycable)
2017-11-26T15:01:44.247816+00:00 app[web.1]: NoMethodError: undefined method []' for nil:NilClass 2017-11-26T15:01:44.247819+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/anyway_config-1.1.2/lib/anyway/rails/config.rb:22:in load_from_file'
2017-11-26T15:01:44.247820+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/anyway_config-1.1.2/lib/anyway/rails/config.rb:14:in load_from_sources' 2017-11-26T15:01:44.247820+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/anyway_config-1.1.2/lib/anyway/config.rb:73:in load'
2017-11-26T15:01:44.247821+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/anyway_config-1.1.2/lib/anyway/config.rb:56:in initialize' 2017-11-26T15:01:44.247822+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/anycable-0.5.0/lib/anycable/config.rb:20:in initialize'
2017-11-26T15:01:44.247822+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/anycable-0.5.0/lib/anycable.rb:34:in new' 2017-11-26T15:01:44.247823+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/anycable-0.5.0/lib/anycable.rb:34:in config'
2017-11-26T15:01:44.247824+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/anycable-0.5.0/lib/anycable/server.rb:13:in start' 2017-11-26T15:01:44.248915+00:00 app[web.1]: /app/bin/anycable:19:in <top (required)>'
2017-11-26T15:01:44.274656+00:00 app[web.1]: Running AnyCable websocket server v0.4.1 on 0.0.0.0:12110 at /cable
2017-11-26T15:01:44.547586+00:00 heroku[web.1]: Process exited with status 1
2017-11-26T15:01:44.561620+00:00 heroku[web.1]: State changed from starting to crashed

Here's what I've done
I pushed the code to both apps on heroku
I manually chmod+x ./bin/anycable with --app-rpc flag
I ran anycable-go -wspath="wss://app-rpc.herokuapp.com/cable"
I've restarted all dynos
I've ran bundle install on heroku

@palkan
Copy link
Member

palkan commented Nov 26, 2017

@Crashtor Looks like your config/anycable.yml exists but empty, because YAML.safe_load returns nil. Is this a case?

@Crashtor
Copy link

Yessss. Here we go! Now, using Devise, I ran into the auth_failed as described in the Heroku tutorial.
Go ahead and close this up Vladimir. Thank you so much for your help!

@palkan
Copy link
Member

palkan commented Nov 26, 2017

🎉 🎉 🎉
We did it)

@birthdaycorp
Copy link

birthdaycorp commented Dec 23, 2019

hi @palkan! i just had this issue, and was wondering if you could clarify something about your answers?

this link says to use config.action_cable.url = 'ws://localhost:3334/cable' in development config. i have that set, but my routes.rb file has mount ActionCable.server => '/cable'. does this mean i'm still using ActionCable? should i remove that from routes? i get the same line in the stacktrace - actioncable (5.2.0) lib/action_cable/server/base.rb:30:in new'`

Update 1

I removed mount ActionCable.server => '/cable' from routes.rb, and now my error is ActionController::RoutingError (No route matches [GET] "/cable"):

@sponomarev
Copy link
Member

@birthdaycorp If it reaches Rails's router, it means that config.action_cable.url is not properly set for the corresponding environment. When AnyCable is used, your frontend should reach websocket backend directly.

Just to make sure, that this option is set and passed properly, check action-cable-url meta tag on a page.

image

@birthdaycorp
Copy link

thanks @sponomarev ! the meta tag in my dev environment says <meta name="action-cable-url" content="ws://localhost:3000/cable">. It was previously on port 3334, but I changed it to 3000 in search of possible reasons as to why it was not working. Neither worked

@sponomarev
Copy link
Member

@birthdaycorp If you want to use AnyCable in all environments including development, make sure that you set config.action_cable.url andws server is running. Nothing related to ActionCable in routes is necessary.

Can you describe what happens when you do all of that?

@birthdaycorp
Copy link

birthdaycorp commented Dec 24, 2019

@sponomarev my config is set as config.action_cable.url = 'ws://localhost:3334/cable' and i'm running bundle exec anycable --server-command "anycable-go --host=localhost --port=3334"

I'll send a message to one user, the message will persist to the db, followed by an ActionCable broadcast [ActionCable] Broadcasting to messages:..{...data...}, and then it hits this:

Started GET "/cable" for ::1 at 2019-12-24 11:31:46 -0800

ActionController::RoutingError (No route matches [GET] "/cable"):
actionpack (5.2.0) lib/action_dispatch/middleware/debug_exceptions.rb:65:in `call'
web-console (3.7.0) lib/web_console/middleware.rb:135:in `call_app'
web-console (3.7.0) lib/web_console/middleware.rb:30:in `block in call'
web-console (3.7.0) lib/web_console/middleware.rb:20:in `catch'
web-console (3.7.0) lib/web_console/middleware.rb:20:in `call'
actionpack (5.2.0) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (5.2.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (5.2.0) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (5.2.0) lib/active_support/tagged_logging.rb:71:in `block in tagged'
activesupport (5.2.0) lib/active_support/tagged_logging.rb:28:in `tagged'
activesupport (5.2.0) lib/active_support/tagged_logging.rb:71:in `tagged'
railties (5.2.0) lib/rails/rack/logger.rb:26:in `call'
actionpack (5.2.0) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
actionpack (5.2.0) lib/action_dispatch/middleware/request_id.rb:27:in `call'
rack (2.0.7) lib/rack/method_override.rb:22:in `call'
rack (2.0.7) lib/rack/runtime.rb:22:in `call'
activesupport (5.2.0) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (5.2.0) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (5.2.0) lib/action_dispatch/middleware/static.rb:127:in `call'
rack (2.0.7) lib/rack/sendfile.rb:111:in `call'
railties (5.2.0) lib/rails/engine.rb:524:in `call'
puma (3.12.1) lib/puma/configuration.rb:227:in `call'
puma (3.12.1) lib/puma/server.rb:660:in `handle_request'
puma (3.12.1) lib/puma/server.rb:474:in `process_client'
puma (3.12.1) lib/puma/server.rb:334:in `block in run'
puma (3.12.1) lib/puma/thread_pool.rb:135:in `block in spawn_thread'

@palkan
Copy link
Member

palkan commented Dec 25, 2019

@birthdaycorp What shows the meta tag when you set config.action_cable.url = 'ws://localhost:3334/cable'? Does it still point to "ws://localhost:3000/cable"?

Where do you set config.action_cable.url: config/application.rb or config/environments/development.rb?

@birthdaycorp
Copy link

The meta tag says <meta name="action-cable-url" content="ws://localhost:3334/cable">. I changed it back to 3334 since 3000 was in use by my rails server.

I have the action_cable.url set in config/environments/development.rb

@sponomarev
Copy link
Member

@birthdaycorp Are you sure that the meta tag is shown on the page which invokes WS connect and? Check all layouts for action_cable_meta_tag.

@birthdaycorp
Copy link

birthdaycorp commented Dec 25, 2019

I have action_cable_meta_tag in my application.html.erb file, so every page on my site has <meta name="action-cable-url" content="ws://localhost:3334/cable"> in the header.

Btw thanks so much for giving this attention on a holiday! <3

Update

When I start my anycable-go server, I get this output:

Started command: anycable-go --host=localhost --port=3334 (pid: 98120)
INFO 2019-12-25T19:28:40.822Z context=main Starting AnyCable 0.6.4 (pid: 98120, open file limit: 256)
INFO 2019-12-25T19:28:40.823Z context=main Handle WebSocket connections at /cable
INFO 2019-12-25T19:28:40.823Z context=main Handle health connections at /health
INFO 2019-12-25T19:28:40.839Z context=rpc RPC pool initialized: localhost:50051
INFO 2019-12-25T19:28:40.842Z context=pubsub Subscribed to Redis channel: __anycable__

INFO 2019-12-25T19:28:40.855Z context=http Starting HTTP server at localhost:3334

It's definitely connected to :3334/cable, but it seems like something is making it use the Rails router.

@birthdaycorp
Copy link

birthdaycorp commented Dec 31, 2019

Update: I think I'm on the right path. I've managed to turn the previous error (ActionController::RoutingError (No route matches [GET] "/cable"):) into WebSocket connection to 'ws://localhost:3334/cable' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED.

Currently getting to the bottom of that, but turns out I just needed t make sure that my action_cable_meta_tag was loaded BEFORE my javascript_include_tag. I figured that out by seeing an example here

@palkan
Copy link
Member

palkan commented Dec 31, 2019

getting to the bottom of that, but turns out I just needed t make sure that my action_cable_meta_tag was loaded BEFORE my javascript_include_tag

Good catch!

I'd suggest to create consumer on DOM load event instead, no reason to initiate the connection
before the page is ready.

WebSocket connection to 'ws://localhost:3334/cable' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED.

Try to run anycable-go with -debug flag and check logs. Probably, authentication problem or RPC server is not running (bundle exec anycable).

@birthdaycorp
Copy link

birthdaycorp commented Jan 2, 2020

Thanks for that DOM load suggestion, it was helpful.

This is so weird, though. I'll change nothing, and it only works half the time.

I'll run rails s and redis-serverand then bundle exec anycable --server-command "anycable-go --host=localhost --port=3334", and AnyCable will "work" in the sense that the anycable terminal spits this out over and over again:

[[AnyCable sid=6y3lH9onvpRGHeZTicREiG] undefined method `user' for nil:NilClass
[AnyCable sid=4bu5UsMf2w0zg8hYZ4VawU] RPC Connect: <AnyCable::ConnectionRequest: path: "/cable", headers: {"REMOTE_ADDR"=>"127.0.0.1", "cookie"=>"wcsid=tZwerwerD9b533C; hblid=wT8x32xbCiqFTWzh3m39Nwerewr35FA; _okdetect=%7B%22token%22%3A%2215752427728670%22%2C%22proto%22%3A%22http%3A%22%2C%22host%22%3A%22localhost%3A4040%22%7D; olfsk=olfsk3463525252472125; _okbk=cd4%3Dtrue%2Cvi5%3D0%2Cvi4%3D1575242773028%2Cvi3%3Dactive%2Cvi2%3Dfalse%2Cvi1%3Dfalse%2Ccd8%3Dchat%2Ccd6%3D0%2Ccd5%3Daway%2Ccd3%3Dfalse%2Ccd2%3D0%2Ccd1%3D0%2C; _ok=1700-237-10-3483; _oklv=1575242826551%2CtZAOL9lfLfqPfKTl3m39N0XFbD9b533C; _project_session=a9932b54c12943434344e9216c27ed; username=napoleon.waelchi; _any_cable_session=SU1nei93RnRIQnpPbUpHMzR4TlJ3ZHk3NXJKTHUzZUZHV2ZEdW1xSGRENm1XZTBkRlZpaU9PSEtSNzRVWzRMVjJDWGNCcmhtcE1mbjZoSFJUYlZ2VzJRa0JoeVFZejZKazdVVkRtU2RiZ3NpdThUZjF6UXpvU28vUkhOQktHU2JkSG12Q0YTImNSU2hKdU1Ocm9zWGNqREExVk5IYWpwbDV4eGZnSm1XUUxNUmoyZ2JqWCtvelZnUHhjVFR5cU5VLS1ZemRPb1haWENkYjVCQk1Xc1NyQWxnPT0%3D--abe49698b042ab3803511681b0f53df58f228a9b"}>](url)

Where is that username=napoleon.waelchi coming from?

@palkan
Copy link
Member

palkan commented Jan 2, 2020

@birthdaycorp

undefined method `user' for nil:NilClass

What's in your ApplicationCable::Connection#connect?

Where is that username=napoleon.waelchi coming from?

It's a part of the cookies.

@birthdaycorp
Copy link

birthdaycorp commented Jan 4, 2020

Thank you so much for your continued help with this! If I open Chrome inspector, I see that the cookie variables are all exactly the same as the output from bundle exec anycable. But that username does not belong to any user model I'm working with.

I followed the Devise integration here, and managed to fix that undefined method 'user' error with a new error: [AnyCable sid=qhREBuLEC3RfUFyzzAngul] An unauthorized connection attempt was rejected. Going off this terminal output, it looks like it is first rejecting, and then connecting with a new AnyCable sid?

[AnyCable sid=DEF-1hhjCkRi3ZpZjzJRDy] An unauthorized connection attempt was rejected
[AnyCable sid=7S7LQnXRwcJdqxyC3yyLbo] RPC Connect: <AnyCable::ConnectionRequest: path: "/cable", headers: {"REMOTE_ADDR"=>"127.0.0.1", "cookie"=>"wcsid=tZAOL9lfLfqPfKTl3m39N0XFbD9b533C; hblid=wT8x32xbCiqFTWzh3m39N0XabCoa35FA; _okdetect=%7B%22token%22%3A%2215752427728670%22%2C%22proto%22%3A%22http%3A%22%2C%22host%22%3A%22localhost%3A4040%22%7D; olfsk=olfsk3463007807472125; _okbk=cd4%3Dtrue%2Cvi5%3D0%2Cvi4%3D1575242773028%2Cvi3%3Dactive%2Cvi2%3Dfalse%2Cvi1%3Dfalse%2Ccd8%3Dchat%2Ccd6%3D0%2Ccd5%3Daway%2Ccd3%3Dfalse%2Ccd2%3D0%2Ccd1%3D0%2C; _ok=1700-237-10-3483; _oklv=1575242826551%2CtZAOL9lfLfqPfKTl3m39N0XFbD9b533C; _project_session=a9932b54c129449974d491e9216c27ed; username=napoleon.waelchi; _any_cable_session=SU1nei93RnRIQnpPbUpHMzR4TlJ3ZHk3NXJKTHUzZUZHV2ZEdW1xSGRENm1XZTBkRlZpaU9PSEtSNzVXUzRMVjJDWGNCcmhtcE1mbjZoSFJUYlZ2VzJRa0JoeVFZejZKazdVVkRtU2RiZ3NpdThUZjF6UXpvU28vUkhOQktHU2JkSG12Q0RNRkNSU2hKdU1Ocm9zWGNqREExVk5IYWpwbDV4eGZnSm1XUUxNUmoyZ2JqWCtvelZnUHhjVFR5cU5VLS1ZemRPb1haWENkYjVCQk1Xc1NyQWxnPT0%3D--abe49698b042ab3803511681be634df58f228a9b"}>

I guess a better way to phrase my question is: why is it taking a user model that I don't have in my database?

This is my channels/application_cable/connection.rb file btw

class Connection < ActionCable::Connection::Base
 identified_by :current_user
  def connect
   self.current_user = find_verified_user || reject_unauthorized_connection
   logger.add_tags 'ActionCable', current_user.username
  end

 protected 
 def find_verified_user
  app_cookies_key = Rails.application.config.session_options[:key] || raise("No session cookies key in config")
  env['rack.session'] = cookies.encrypted[app_cookies_key]
  Warden::SessionSerializer.new(env).fetch(:user)
 end
end

@palkan
Copy link
Member

palkan commented Jan 5, 2020

But that username does not belong to any user model I'm working with.

Do you set cookies[:username] somewhere in your code? Or have your tried to run anycable_demo app (we have such cookies usage there)? Probably, just a cookie left from something else. Have you tried to clear the browser cookies?

@birthdaycorp
Copy link

birthdaycorp commented Jan 13, 2020

Turns out I did have a cookie left over from the anycable_demo app. Clearing my cookies solved that one. :)

I'm still trying to figure out how to make this work, but... would you have any idea why the anycable console keeps spitting out [AnyCable sid=ZyR-1n5t1oapkFM29g8fL0] An unauthorized connection attempt was rejected before and/or after every successful connection?

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

7 participants