anycable-rails: About .. action_cable.js:241 WebSocket connection to 'ws://localhost:50051/cable' failed: error

Hi, im a beginner RoR student. and it was so confusing cause i don’t know where(or what) ther problem is… so if you can give some advice, it will really helpful. Thanks for your kindness.

Tell us about your environment

**Using goorm ide ** (online cloud development system) https://ide.goorm.io/

Ruby version: 2.6.5

Rails version: 6.0.4

anycable gem version: 1.1.1

anycable-rails gem version: 1.1.2

grpc gem version: 1.38.0

What did you do?

==== Installed … (in my upper gemfile)

gem ‘bootstrap’, ‘~> 4.0’ gem ‘autoprefixer-rails’ gem “anycable-rails”, “~> 1.1” gem ‘devise’

when using Redis broadcast adapter

gem “redis”, “>= 4.0” gem ‘grpc’

==== and the base is same … https://www.nopio.com/blog/rails-chat-application-actioncable/ or https://github.com/nopio/facebook-chat-part2

=== and after that reference( https://medium.com/geekculture/actioncable-to-anycable-c9d9d54665f0 )

=== config/cable.yml

development: adapter: anycable

production: adapter: anycable

=== config/environments/production.rb

Rails.application.configure do config.after_initialize do config.action_cable.url = “wss://studying-app-iloag.run.goorm.io:50051/cable” config.action_cable.allowed_request_origins = [‘https://studying-app-iloag.run.goorm.io’] end …

=== config/environments/development.rb

Rails.application.configure do config.after_initialize do config.action_cable.url = “ws://localhost:50051/cable” config.action_cable.allowed_request_origins = [‘http://localhost:3000’] end …

=== config/anycable.yml

default: &default access_logs_disabled: false rpc_host: “127.0.0.1:50051” log_grpc: false broadcast_adapter: redis redis_channel: “anycable

development: rpc_host: “localhost:50051” # Host and port of the RPC host redis_url: “redis://development_redis_url:6379”

production: rpc_host: “localhost:50051” # Host and port of the RPC host redis_url: “redis://production_redis_url:6379”

test: <<: *default

=== on terminal

sudo apt-get install golang-go sudo apt update sudo apt install golang-go go get -u -f github.com/anycable/anycable-go/cmd/anycable-go

and

i met the truble. so i googling…

found this. https://github.com/anycable/anycable-rails/issues/115

and,

layouts/application.html.erb

<%= action_cable_meta_tag %>         <<<added...
<%= csrf_meta_tags %>

fount this. https://github.com/anycable/anycable-rails/issues/127

and…

config/environment/development.rb

config/application.rb.

  • config.session_store :cache_store
  • config.session_store :cookie_store, key: ‘_any_session’

routes.rb

… mount ActionCable.server => ‘/cable’ << added… end

but, nothing changed…haha…

What did you expect to happen?

I expected that I can make realtime messaging web app

What actually happened?

i don’t sure that I installed anycable-go correctly. … when i enter "anycable-go"at terminal, message “can’t find command” printed…

when i click send button, window page reloaded and added http address part like"&user_id=1&body=wdfsdf" and on my Chrome console, "WebSocket connection to ‘ws://localhost:50051/cable’ failed: " printed intevally…

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17 (8 by maintainers)

Most upvoted comments

@kerbong, looks like Redis server still isn’t running. You have to launch it, ensure it is running and listening on localhost port 6379 (these are defaults) before launching either anycable or rails. Redis is essential as all communication between anycable and rails is going through it.

To start Redis on Linux you should execute command like this:

sudo systemctl start redis

and check if it is running like this (it should be on active (running) state):

$ sudo systemctl status redis.service        
● redis.service - Advanced key-value store
     Loaded: loaded (/usr/lib/systemd/system/redis.service; disabled; vendor preset: disabled)
     Active: active (running) since Tue 2021-07-27 15:16:21 MSK; 4min 32s ago
   Main PID: 8832 (redis-server)
     Status: "Ready to accept connections"
      Tasks: 5 (limit: 38350)
     Memory: 4.0M
        CPU: 916ms
     CGroup: /system.slice/redis.service
             └─8832 /usr/bin/redis-server 127.0.0.1:6379

And you can check connectivity with redis-cli tool (should be installed along Redis server, but not sure):

$ redis-cli -h 127.0.0.1 -p 6379     
127.0.0.1:6379>

But if you’re getting following message, then it is not ready to be used yet:

$ redis-cli -h 127.0.0.1 -p 6379            
Could not connect to Redis at 127.0.0.1:6379: Connection refused
not connected> 

If you run Redis and application inside Docker containers then you need to use Docker hostnames in anycable configuration.