anycable / anycable-rails

AnyCable for Ruby on Rails applications
https://anycable.io
MIT License
499 stars 35 forks source link

About .. action_cable.js:241 WebSocket connection to 'ws://localhost:50051/cable' failed: error #159

Closed kerbong closed 2 years ago

kerbong commented 3 years ago

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.

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?

1. i don't sure that I installed anycable-go correctly. ... when i enter "anycable-go"at terminal, message "can't find command" printed...

2. 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...

palkan commented 3 years ago

"ws://localhost:50051/cable"

This: 50051 is the gRPC port, WebSocket server is listening on :8080 by default (check the output of the anycable-go command).

kerbong commented 3 years ago

@palkan Thanks your fast response!! i tried your advise and then another googling advises... and then things changes..

javascript/channels/consumer.js ` import { createConsumer } from "@rails/actioncable"

export default createConsumer('wss://studying-app-iloagg.run.goorm.io:8080/cable') ` and...

Chrome console log changed !!!

"action_cable.js:259 WebSocket connection to 'wss://studying-app-iloagg.run.goorm.io:8080/cable' failed: WebSocket is closed before the connection is established."

======

how can i know anycable-go installed correctly ?? when i write 'anycable-go' in my terminal, it shows "can't find command... "

if there was not anycable-go... then where can i fix the code the upper one..

=== 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

thanks again!!

palkan commented 3 years ago

how can i know anycable-go installed correctly ?? when i write 'anycable-go' in my terminal, it shows "can't find command... "

What is the output of the go get -u -f github.com/anycable/anycable-go/cmd/anycable-go command?

Anyway, I'd suggest using pre-built binaries (see Releases) instead of building from source.

kerbong commented 3 years ago

when i write "go get -u -f github.com/anycable/anycable-go/cmd/anycable-go" in terminal

go get: -f flag is a no-op when using modules go: downloading google.golang.org/genproto v0.0.0-20210722135532-667f2b7c528f

... and nothing happen.

====

but... there is something changed !!!

i followed getting started from your anycable documents (https://docs.anycable.io/rails/getting_started)

and now, if i put " anycable-go --host=localhost --port=8080 " in terminal or "anycable-go"

=== root@goorm:/workspace/studying_app# anycable-go --host=localhost --port=8080 INFO 2021-07-23T03:37:09.636Z context=main Starting AnyCable 1.1.2-bbf4cae (pid: 745, open file limit: 1024) INFO 2021-07-23T03:37:09.640Z context=main Handle WebSocket connections at http://localhost:8080/cable INFO 2021-07-23T03:37:09.640Z context=main Handle health connections at http://localhost:8080/health WARN 2021-07-23T03:37:09.643Z context=pubsub Redis connection failed: dial tcp 127.0.0.1:6379: connect: connection refused INFO 2021-07-23T03:37:09.644Z context=pubsub Next Redis reconnect attempt in 3s INFO 2021-07-23T03:37:09.644Z context=rpc RPC controller initialized: localhost:50051 (concurrency: 28, enable_tls: false, proto _versions: v1) INFO 2021-07-23T03:37:12.645Z context=pubsub Reconnecting to Redis... WARN 2021-07-23T03:37:12.646Z context=pubsub Redis connection failed: dial tcp 127.0.0.1:6379: connect: connection refused

=== root@goorm:/workspace/studying_app# anycable-go INFO 2021-07-23T03:37:36.737Z context=main Starting AnyCable 1.1.2-bbf4cae (pid: 779, open file limit: 1024) INFO 2021-07-23T03:37:36.747Z context=main Handle WebSocket connections at http://localhost:8080/cable INFO 2021-07-23T03:37:36.756Z context=main Handle health connections at http://localhost:8080/health WARN 2021-07-23T03:37:36.748Z context=pubsub Redis connection failed: dial tcp 127.0.0.1:6379: connect: connection refused INFO 2021-07-23T03:37:36.760Z context=pubsub Next Redis reconnect attempt in 3s INFO 2021-07-23T03:37:36.753Z context=rpc RPC controller initialized: localhost:50051 (concurrency: 28, enable_tls: false, proto _versions: v1) INFO 2021-07-23T03:37:39.761Z context=pubsub Reconnecting to Redis... WARN 2021-07-23T03:37:39.762Z context=pubsub Redis connection failed: dial tcp 127.0.0.1:6379: connect: connection refused

and, i'm using IDE system. so when i test my web i'm using the url "https://studying-app-iloagg.run.goorm.io/" not localhost:3000.

the url means 8080 port.

veryveryvery thanks again...!!

palkan commented 3 years ago

Cool!

Now you need to resolve this (install Redis):

Redis connection failed: dial tcp 127.0.0.1:6379: connect: connection refused

kerbong commented 3 years ago

Thanks for your replying!!

i installed by "gem install redis" (is it right?)

and... rails s -b 0.0.0.0 -p 3000 -p 8080

and anycable-go

then...

======< in my terminal >======= INFO 2021-07-23T14:11:22.164Z context=main Starting AnyCable 1.1.2-bbf4cae (pid: 3432, open file limit: 1024) INFO 2021-07-23T14:11:22.164Z context=main Handle WebSocket connections at http://localhost:8080/cable INFO 2021-07-23T14:11:22.164Z context=main Handle health connections at http://localhost:8080/health WARN 2021-07-23T14:11:22.165Z context=pubsub Redis connection failed: dial tcp 127.0.0.1:6379: connect: connection refused INFO 2021-07-23T14:11:22.165Z context=pubsub Next Redis reconnect attempt in 3s INFO 2021-07-23T14:11:22.165Z context=rpc RPC controller initialized: localhost:50051 (concurrency: 28, enable_tls: false, proto _versions: v1) WebSocket server at http://localhost:8080 stopped: listen tcp 127.0.0.1:8080: bind: address already in use

======< in my server side >======= Started GET "/cable" for 172.17.0.1 at 2021-07-23 14:21:11 +0000 Cannot render console from 172.17.0.1! Allowed networks: 127.0.0.0/127.255.255.255, ::1 You're trying to connect to Action Cable server while using AnyCable. See https://docs.anycable.io/troubleshooting?id=server-raise s-an-argumenterror-exception-when-client-tries-to-connect Finished "/cable/" [AnyCable] for 172.17.0.1 at 2021-07-23 14:21:11 +0000 (Closed)

======< client chrome console >======= WebSocket connection to 'wss://studying-app-iloagg.run.goorm.io/cable' failed:

thanks for your very kindful reply despite im so beginner and can't doing well.

Thanks

palkan commented 3 years ago

i installed by "gem install redis" (is it right?)

Not really; it's a client library, you need a server itself.

Like, apt install redis or smth like that.

kerbong commented 3 years ago

i installed by "gem install redis" (is it right?)

Not really; it's a client library, you need a server itself.

Like, apt install redis or smth like that.

@palkan Thanks. I did it. But there is nothing changed.....

in my client chrome console WebSocket connection to 'wss://studying-app-iloag.run.goorm.io/cable' failed:

So i changed may time consumer.js

import { createConsumer } from "@rails/actioncable" export default createConsumer('wss://studying-app-iloag.run.goorm.io/cable')

where the url in it.

changed like ws://studying-app-iloag.run.goorm.io/cable wss://studying-app-iloag.run.goorm.io:8080/cable

ws://studying-app-iloagg.run.goorm.io/cable (where 8080port connected) ws://studying-app-iloagg.run.goorm.io:8080/cable

so... i wanna know where the problem is...

port forwarding studying-app-iloag.run.goorm.io port 3000 studying-app-iloagg.run.goorm.io port 8080 studying-app-iloaggg.run.goorm.io port 6379

First, I did rails server -b 0.0.0.0 -p 3000

Second anycable-go

Third turn on the url

....

so, where is the problem? or you need more information to help me out?

i can't figure out cause im just so beginner... sorry and very thankful about your consistant reply.

Thanks.

palkan commented 3 years ago

or you need more information to help me out?

Yeah. Do you have access to logs? Can you run anycable-go with -debug flag and capture its output? The question is whether there is a forwarding problem (sockets cannot reach the WS server) or it's something related to services communication (then, we should see something in logs).

kerbong commented 3 years ago

@palkan Thanks!!!!!!!

DEBUG 2021-07-27T11:50:28.584Z context=main 🔧 🔧 🔧 Debug mode is on 🔧 🔧 🔧 INFO 2021-07-27T11:50:28.585Z context=main Starting AnyCable 1.1.2-bbf4cae (pid: 606, open file limit: 1024) DEBUG 2021-07-27T11:50:28.589Z context=disconnector Calls rate: 10ms WARN 2021-07-27T11:50:28.600Z context=pubsub Redis connection failed: dial tcp 127.0.0.1:6379: connect: connection refused INFO 2021-07-27T11:50:28.612Z context=pubsub Next Redis reconnect attempt in 3s INFO 2021-07-27T11:50:28.612Z context=main Handle WebSocket connections at http://localhost:8080/cable INFO 2021-07-27T11:50:28.617Z context=main Handle health connections at http://localhost:8080/health DEBUG 2021-07-27T11:50:28.626Z context=main Go pools initialized (broadcast: 16) INFO 2021-07-27T11:50:28.618Z context=rpc RPC controller initialized: localhost:50051 (concurrency: 28, enable_tls: false, proto _versions: v1) DEBUG 2021-07-27T11:50:28.628Z context=http Starting WebSocket server at http://localhost:8080 DEBUG 2021-07-27T11:50:28.628Z context=metrics No metrics writers. Disable metrics rotation INFO 2021-07-27T11:50:31.615Z context=pubsub Reconnecting to Redis... WARN 2021-07-27T11:50:31.615Z context=pubsub Redis connection failed: dial tcp 127.0.0.1:6379: connect: connection refused INFO 2021-07-27T11:50:31.616Z context=pubsub Next Redis reconnect attempt in 25s

.....

after some Redis reconnect attempts....

!!! Subscriber failed !!! Redis reconnect attempts exceeded

On this situation, if i send some message to another user(i made), happened nothing. Just added user-id and message content at the end of url like
"http://studying-app-iloag.run.goorm.io/?conversation_id=1&user_id=1&body=hihihi"

So... is there any more needed information that i can give you?

Envek commented 3 years ago

@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.

kerbong commented 3 years ago

@Envek Thanks!!! but i can't "sudo systemctl start redis". If i did it terminal, message "System has not been booted with systemd as init system (PID 1). Can't operate." appeared.

and, on terminal

$ redis-server

there are lines on terminal

13151:M 27 Jul 17:09:37.100 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is s et to the lower value of 128. 13151:M 27 Jul 17:09:37.100 # Server initialized 13151:M 27 Jul 17:09:37.100 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix t his issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' fo r this to take effect. 13151:M 27 Jul 17:09:37.100 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled ' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is di sabled. 13151:M 27 Jul 17:09:37.100 DB loaded from disk: 0.000 seconds 13151:M 27 Jul 17:09:37.100 Ready to accept connections

....

is it right??

and I saw some stackoverflow advise like, "you should use 6379/1 at redis server if you want to use both your main Rails and Redis."

So.. in my anycable.yml

` default: &default

rpc_host: "127.0.0.1:50051"

log_grpc: false

broadcast_adapter: redis

redis_channel: "anycable"

development: <<: *default redis_url: redis://localhost:6379/1

test: <<: *default

production: <<: *default redis_url: redis://studying-app-iloag.run.goorm.io:6379/1 access_logs_disabled: false `

And I didn't use Docker... (i don't know what it is...haha... i'm using IDE cloud system, not cloud9 but goorm IDE..)

Envek commented 3 years ago
13151:M 27 Jul 17:09:37.100 * Ready to accept connections

That's right. Now, while it is running, you can use any cables you want.


P.S> Please use Markdown formatting in your messages. They are painful to read and understand. Help us to help you!

kerbong commented 3 years ago

Thanks your advice again..!!

========

when i write this on terminal apt install redis => already installed messages appears

and, also i can get 13151:M 27 Jul 17:09:37.100 * Ready to accept connections

but I got some trouble sending message to other testing user by anycables.

trial 1

first. i ran the rails server

second. and at the server terminal redis-server (Ready to accept connections)

third. I got some trouble sending message to other testing user. there was nothing changed.. x _ x

trial 2

first. rails-server

second. anycable-go

third. I got some trouble sending message to other testing user. there was nothing changed.. x _ x

and, client console WebSocket connection to 'wss://studying-app-iloag.run.goorm.io/cable' failed: repeated,

server-side console You're trying to connect to Action Cable server while using AnyCable. See https://docs.anycable.io/troubleshooting?id=server-raise s-an-argumenterror-exception-when-client-tries-to-connect Finished "/cable/" [AnyCable] for 172.17.0.1 at 2021-07-29 18:36:17 +0000 (Closed) Started GET "/cable" for 172.17.0.1 at 2021-07-29 18:36:29 +0000 Cannot render console from 172.17.0.1! Allowed networks: 127.0.0.0/127.255.255.255, ::1 repeated...

questions

1. is there a problem ?? You're trying to connect to Action Cable server while using AnyCable. See https://docs.anycable.io/troubleshooting?id=server-raise s-an-argumenterror-exception-when-client-tries-to-connect (i can't understand that url's content.. and i think that is not a right way for me.)

1-1. but if there is, what's the different between anycable and anycable-go??

2. I guess that the problem is cause of port forwarding.

when i Changed app/javascript/channel/consumer.js code,

2-1. export default createConsumer('wss://studying-app-iloaggg.run.goorm.io/cable') << port 6379 action_cable.js:241 WebSocket connection to 'wss://studying-app-iloaggg.run.goorm.io/cable' failed: Error during WebSocket handshake: Invalid status line

2-2. export default createConsumer('wss://studying-app-iloagg.run.goorm.io/cable') << port 8080 WebSocket connection to 'wss://studying-app-iloagg.run.goorm.io/cable' failed: Error during WebSocket handshake: Unexpected response code: 404

2-3. export default createConsumer('wss://studying-app-iloag.run.goorm.io/cable') << port 3000 action_cable.js:241 WebSocket connection to 'wss://studying-app-iloag.run.goorm.io/cable' failed: Error during WebSocket handshake: Unexpected response code: 200

so,, thanks again your help!!!

kerbong commented 3 years ago

@palkan @Envek Thanks!!!!! i got some advances on my anycable base realtime test app.!!!!!

in my client console(chrome)

<head> ... <meta name="action-cable-url" content="ws://studying- ......... .io:8080/cable">

when i put anycable-go into terminal

` INFO 2021-08-01T19:19:04.341Z context=main Starting AnyCable 1.1.2-bbf4cae (pid: 19330, open file limit: 1024) INFO 2021-08-01T19:19:04.341Z context=main Handle WebSocket connections at http://localhost:8080/cable INFO 2021-08-01T19:19:04.341Z context=main Handle health connections at http://localhost:8080/health INFO 2021-08-01T19:19:04.342Z context=pubsub Subscribed to Redis channel: anycable

INFO 2021-08-01T19:19:04.343Z context=rpc RPC controller initialized: localhost:50051 (concurrency: 28, enable_tls: false, proto_versions: v1)`

and when i send some message like Hey!! to another test user, in my server console

Processing by MessagesController#create as JS Parameters: {"utf8"=>"✓", "message"=>{"user_id"=>"1", "conversation_id"=>"3", "body"=>"Hey!!"}, "authenticity_token"=>"Gphck0oABM79NGZDKWdB5Jlwins52fhIxnjKK/jq wUunP2u8LfkmUxfLPwUAM29MugIMk5Q5xhOCtSqWK6lAGg==", "commit"=>"보내기", "conversation_id"=>"3"} User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ? [["id", 1], ["LIMIT", 1]] Conversation Load (0.1ms) SELECT "conversations".* FROM "conversations" WHERE "conversations"."id" = ? LIMIT ? [["id", 3], ["LIMIT", 1]] ↳ app/controllers/messages_controller.rb:3:increate' User Load (0.2ms) SELECT "users". FROM "users" WHERE "users"."id" = ? [["id", 4]] ↳ app/controllers/messages_controller.rb:3:in create' (0.1ms) begin transaction ↳ app/controllers/messages_controller.rb:4:increate' User Load (0.2ms) SELECT "users". FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 1], ["LIMIT", 1]] ↳ app/controllers/messages_controller.rb:4:in create' Message Create (1.1ms) INSERT INTO "messages" ("body", "user_id", "conversation_id", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?) [["body", "Hey!!"], [ user_id", 1], ["conversation_id", 3], ["created_at", "2021-08-01 19:50:01.582102"], ["updated_at", "2021-08-01 19:50:01.582102"]] ↳ app/controllers/messages_controller.rb:4:increate' (15.8ms) commit transaction ↳ app/controllers/messages_controller.rb:4:in create' [ActiveJob] Enqueued MessageBroadcastJob (Job ID: fb2493e2-4014-470a-b016-d65824cb54bc) to Async(default) with arguments: #<GlobalID:0x00005594ad50ba80 @uri=#<UR I::GID gid://goorm-rails-app/Message/36>> Message Load (0.2ms) SELECT "messages".* FROM "messages" WHERE "messages"."id" = ? LIMIT ? [["id", 36], ["LIMIT", 1]] [ActiveJob] [MessageBroadcastJob] [fb2493e2-4014-470a-b016-d65824cb54bc] Performing MessageBroadcastJob (Job ID: fb2493e2-4014-470a-b016-d65824cb54bc) from Async (default) enqueued at 2021-08-01T19:50:01Z with arguments: #<GlobalID:0x00005594ad5ba5d0 @uri=#<URI::GID gid://goorm-rails-app/Message/36>> [ActiveJob] [MessageBroadcastJob] [fb2493e2-4014-470a-b016-d65824cb54bc] User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id , 1], ["LIMIT", 1]] [ActiveJob] [MessageBroadcastJob] [fb2493e2-4014-470a-b016-d65824cb54bc] ↳ app/jobs/message_broadcast_job.rb:5:inperform' Rendered messages/_message.html.erb (Duration: 0.1ms | Allocations: 11) [ActiveJob] [MessageBroadcastJob] [fb2493e2-4014-470a-b016-d65824cb54bc] Conversation Load (0.2ms) SELECT "conversations".* FROM "conversations" WHERE "conver sations"."id" = ? LIMIT ? [["id", 3], ["LIMIT", 1]] [ActionCable] Broadcasting to conversationchannel: {:message=>"

  • \n <div class=\"row\">\n <div class=\"message-sent\">\n Hey!!\n
  • \n
    \n

    "} Completed 200 OK in 72ms (Views: 2.1ms | ActiveRecord: 17.6ms | Allocations: 12739)

    [ActiveJob] [MessageBroadcastJob] [fb2493e2-4014-470a-b016-d65824cb54bc] ↳ app/jobs/message_broadcast_job.rb:6:in perform' [ActiveJob] [MessageBroadcastJob] [fb2493e2-4014-470a-b016-d65824cb54bc] User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id , 4], ["LIMIT", 1]] [ActiveJob] [MessageBroadcastJob] [fb2493e2-4014-470a-b016-d65824cb54bc] ↳ app/models/conversation.rb:22:inopposed_user' [ActiveJob] [MessageBroadcastJob] [fb2493e2-4014-470a-b016-d65824cb54bc] Rendered messages/_message.html.erb (Duration: 0.1ms | Allocations: 11) [ActiveJob] [MessageBroadcastJob] [fb2493e2-4014-470a-b016-d65824cb54bc] [ActionCable] Broadcasting to conversations-1: {:message=>"

  • \n <div class=\"row\">\n <div class=\"message-sent\">\n Hey!!\n \n \n
  • ", :conversation_id=>3} [ActiveJob] [MessageBroadcastJob] [fb2493e2-4014-470a-b016-d65824cb54bc] CACHE User Load (0.0ms) SELECT "users". FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 1], ["LIMIT", 1]] [ActiveJob] [MessageBroadcastJob] [fb2493e2-4014-470a-b016-d65824cb54bc] ↳ app/models/conversation.rb:22:in `opposed_user' [ActiveJob] [MessageBroadcastJob] [fb2493e2-4014-470a-b016-d65824cb54bc] Message Load (0.3ms) SELECT "messages". FROM "messages" WHERE "messages"."conversati on_id" = ? [["conversation_id", 3]] [ActiveJob] [MessageBroadcastJob] [fb2493e2-4014-470a-b016-d65824cb54bc] ↳ app/views/conversations/_conversation_content.html.erb:1 [ActiveJob] [MessageBroadcastJob] [fb2493e2-4014-470a-b016-d65824cb54bc] Rendered messages/_message.html.erb (Duration: 0.1ms | Allocations: 12) [ActiveJob] [MessageBroadcastJob] [fb2493e2-4014-470a-b016-d65824cb54bc] Rendered messages/_message.html.erb (Duration: 0.1ms | Allocations: 11) [ActiveJob] [MessageBroadcastJob] [fb2493e2-4014-470a-b016-d65824cb54bc] Rendered conversations/_conversation_content.html.erb (Duration: 3.1ms | Allocations: 963) [ActiveJob] [MessageBroadcastJob] [fb2493e2-4014-470a-b016-d65824cb54bc] Rendered conversations/_conversation.html.erb (Duration: 6.6ms | Allocations: 2251) [ActiveJob] [MessageBroadcastJob] [fb2493e2-4014-470a-b016-d65824cb54bc] Rendered messages/_message.html.erb (Duration: 0.1ms | Allocations: 9) [ActiveJob] [MessageBroadcastJob] [fb2493e2-4014-470a-b016-d65824cb54bc] [ActionCable] Broadcasting to conversations-4: {:window=>"
  • \n <div class=\"panel pan el-default\" data-conversation-id=\"3\">\n <div class=\"panel-heading\">\n <a class=\"toggle-window\" href=\"\">user-1@example.com\n <a class=\" btn btn-default btn-xs pull-right\" data-remote=\"true\" rel=\"nofollow\" data-method=\"post\" href=\"/conversations/3/close\">x\n \n\n <div clas s=\"panel-body\" style=\"display: none;\">\n <div class=\"messages-list\">\n \n \n\n\t <form class=\"new_message\" id=\"new_message\" action=\"/conversations/3/messages\" accept-charset=\"UTF-8\" data-remote=\ "true\" method=\"post\"><input name=\"utf8\" type=\"hidden\" value=\"✓\" />\n <input value=\"4\" type=\"hidden\" name=\"message[user_id]\" id=\"mes sage_user_id\" />\n <input value=\"3\" type=\"hidden\" name=\"message[conversation_id]\" id=\"message_conversation_id\" />\n\t\t<input name=\"authenticity _token\" \n type=\"hidden\" \n value=\"XF/QaZ1uS90DJ+vosbwK/gljKPAVOrYpO5kaK085WgRVZyvYUYkVoLsyzRj/A6VCeYHf7871z8WCxHtQgyHcxg==\"/>\n \n\t\t\t<input style=\"width:80%; margin-top:7px;\" type=\"text\" name=\"message[body]\" id=\"message_body\" />\n\t\t\n \n\t\t\ t<input type=\"submit\" name=\"commit\" value=\"보내기\" class=\"btn btn-success\" style=\"width:15%;\" data-disable-with=\"보내기\" />\n\t\t\n\n\n \t\t\n\t\t\n \n \n
  • ", :message=> "
  • \n <div class=\"row\">\n <div class=\"message-received\">\n Hey!!\n \n \n
  • ", :conversation_id=>3} [ActiveJob] [MessageBroadcastJob] [fb2493e2-4014-470a-b016-d65824cb54bc] Performed MessageBroadcastJob (Job ID: fb2493e2-4014-470a-b016-d65824cb54bc) from Async( default) in 48.63ms`

    There are two problems.

    First.

    Two kinds of errors appeared from client console.

    If i change the consumer.js

    export default createConsumer('ws://studying-app-iloagg.run.goorm.io:8080/cable') ==> WebSocket connection to 'ws://studying-app-iloagg.run.goorm.io:8080/cable' failed: WebSocket is closed before the connection is established.

    export default createConsumer('ws://localhost:8080/cable')
    ==> WebSocket connection to 'ws://localhost:8080/cable' failed

    Second.

    So that I can't see the send message Hey!! realtime...

    Thanks again and hope your patience persistent...!!!!! And Thanks again for reading my messy questions. ^^

    Envek commented 3 years ago
    export default createConsumer('ws://studying-app-iloagg.run.goorm.io:8080/cable')
    ==> WebSocket connection to 'ws://studying-app-iloagg.run.goorm.io:8080/cable' failed: WebSocket is closed before the connection is established.

    That's probably because your WebSocket connection isn't properly proxied to anycable-go process (or is forwarded to your web application process instead, which is correct for ActionCable, but wrong for AnyCable).

    I don't really understand how this Goorm IDE is working and how it launches your application, but, in general, when there is a load balancer in front of your application, it MUST support WebSocket protocol and, sometimes, also must be additionally configured (e.g. see example for Nginx)

    kerbong commented 3 years ago

    @Envek Thanks. After your reply I've tried another real time chat testing web. And, I can send real-time messaging with action-cable.

    Then, i tried anycable install.(following your steps.)

    So, now i vaguely understand about anycable, but except which is properly proxied to anycable-go. When I send message, there(in Chrome console) is no-error about anything.

    But i got error action_cable.js:241 WebSocket connection to 'ws://localhost:8080/cable' failed:

    details open @ action_cable.js:241 reopen @ action_cable.js:276 reconnectIfStale @ action_cable.js:154 (anonymous) @ action_cable.js:130

    ====== and i dont understand what you mentioned.

    That's probably because your WebSocket connection isn't properly proxied to anycable-go process (or is forwarded to your web application process instead, which is correct for ActionCable, but wrong for AnyCable).

    What's the correct proxy to anycable-go??