Comments (36)
@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
.
from anycable-rails.
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.
from anycable-rails.
@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"
from anycable-rails.
@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.
from anycable-rails.
@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?
from anycable-rails.
@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
?
from anycable-rails.
@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
.
from anycable-rails.
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
).
from anycable-rails.
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.
from anycable-rails.
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?
from anycable-rails.
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)?
from anycable-rails.
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
from anycable-rails.
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
.
from anycable-rails.
@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.
from anycable-rails.
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.
from anycable-rails.
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.
from anycable-rails.
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
from anycable-rails.
@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
from anycable-rails.
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')
from anycable-rails.
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
from anycable-rails.
@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.
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 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: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.
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.
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.....
from anycable-rails.
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
from anycable-rails.
@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.
from anycable-rails.
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
from anycable-rails.
@Crashtor Looks like your config/anycable.yml
exists but empty, because YAML.safe_load
returns nil
. Is this a case?
from anycable-rails.
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!
from anycable-rails.
π π π
We did it)
from anycable-rails.
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"):
from anycable-rails.
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
from anycable-rails.
@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'
from anycable-rails.
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
from anycable-rails.
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.
from anycable-rails.
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
from anycable-rails.
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-server
and 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?
from anycable-rails.
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
from anycable-rails.
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?
from anycable-rails.
Related Issues (20)
- can't run bundle exec anycable HOT 9
- AnyCable Deployment Guide HOT 4
- Nearly Complete Deployment w/Anycable HOT 3
- Does anycable truly depend on latest & greatest Ruby/Rails? HOT 2
- Rails 7 compatibility issue HOT 41
- log4r broken in development HOT 6
- Flutter app is connecting fine to wss, but actual subscribe is throwing unknown command type errors HOT 2
- Cannot call handle_open to handle JWT expiration HOT 2
- Permissions Error when Deploying AnyCable to Heroku HOT 11
- RPC memory usage - pods OOMkilled with 4GB allocated per pod HOT 4
- Anycable-rails and Seachkick together hangs the server HOT 2
- Tenant getting lost during identifier serialization HOT 3
- ActionController::RoutingError (No route matches [GET] "/cable")
- Devise authentication/sessions not working HOT 1
- What's the best way to close open connections on forking? HOT 5
- Issue with anycable-rpc crashing on start `terminate called after throwing an instance of 'std::logic_error'` HOT 2
- ActiveSupport::Logger.broadcast method is dropped HOT 8
- Issues with gRPC Communication between AnyCable Go and AnyCable Rails HOT 2
- ActionController::RoutingError (No route matches [GET] "/cable"): HOT 7
- reconnect option not forwarded in ActionCable::RemoteConnections::RemoteConnection#disconnect HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from anycable-rails.