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

JRuby ActionCable - Successfully upgraded to WebSocket #2962

Open
Unknown-Guy opened this issue Sep 16, 2022 · 2 comments
Open

JRuby ActionCable - Successfully upgraded to WebSocket #2962

Unknown-Guy opened this issue Sep 16, 2022 · 2 comments

Comments

@Unknown-Guy
Copy link

Describe the bug
Is websockets supported on JRuby?

Updates through websocket work on first request, after reloading page, stops working, log repeatedly gets:

Started GET "/cable" for 0:0:0:0:0:0:0:1 at 2022-09-16 13:21:08 +0300
Started GET "/cable/" [WebSocket] for 0:0:0:0:0:0:0:1 at 2022-09-16 13:21:08 +0300
Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket)

Puma config default:

max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
threads min_threads_count, max_threads_count
worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development"
port ENV.fetch("PORT") { 3000 }
environment ENV.fetch("RAILS_ENV") { "development" }
pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }
plugin :tmp_restart

To Reproduce
Took https://github.com/hotwired/hotwire-rails-demo-chat, updated Gemfile to use jRuby

ruby '2.6.8', engine: 'jruby', engine_version: '9.3.7.0'

gem 'activerecord'
gem 'activerecord-jdbcsqlite3-adapter', '~> 61.1', platform: :jruby

Not using docker, run it with:

bin/rails s

Expected behavior
Websocket keeps working

Desktop (please complete the following information):

  • OS: MacOS
  • 5.6.5-java
@cafedomancer
Copy link
Contributor

cafedomancer commented Oct 19, 2022

I have confirmed that I cannot reproduce the bug on CRuby and I can reproduce it on JRuby. Here is the entire codebase which I used for reproducing. https://github.com/cafedomancer/hotwire-rails-demo-chat/tree/jruby

Environment

$ uname -a
Linux localhost 5.10.0-18-amd64 #1 SMP Debian 5.10.140-1 (2022-09-02) x86_64 GNU/Linux
$ lsb_release -a
No LSB modules are available.
Distributor ID:	Debian
Description:	Debian GNU/Linux 11 (bullseye)
Release:	11
Codename:	bullseye

CRuby

$ ruby -v
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux]

Just after running bin/rails server

Screen Shot 2022-10-19 at 21 50 51

Started GET "/rooms/1" for 153.205.220.93 at 2022-10-19 13:09:43 +0000
Cannot render console from 153.205.220.93! Allowed networks: 127.0.0.0/127.255.255.255, ::1
Processing by RoomsController#show as HTML
  Parameters: {"id"=>"1"}
  Room Load (0.2ms)  SELECT "rooms".* FROM "rooms" WHERE "rooms"."id" = ? LIMIT ?  [["id", 1], ["LIMIT", 1]]
  ↳ app/controllers/rooms_controller.rb:35:in `set_room'
  Rendering layout layouts/application.html.erb
  Rendering rooms/show.html.erb within layouts/application
  Rendered rooms/_room.html.erb (Duration: 0.1ms | Allocations: 14)
  Message Load (0.2ms)  SELECT "messages".* FROM "messages" WHERE "messages"."room_id" = ?  [["room_id", 1]]
  ↳ app/views/rooms/show.html.erb:15
  Rendered collection of messages/_message.html.erb [5 times] (Duration: 0.5ms | Allocations: 267)
  Rendered rooms/show.html.erb within layouts/application (Duration: 4.5ms | Allocations: 1499)
  Rendered layout layouts/application.html.erb (Duration: 9.3ms | Allocations: 6889)
Completed 200 OK in 11ms (Views: 9.6ms | ActiveRecord: 0.3ms | Allocations: 7589)


Finished "/cable/" [WebSocket] for 153.205.220.93 at 2022-10-19 13:09:43 +0000
Turbo::StreamsChannel stopped streaming from Z2lkOi8vY2hhdC9Sb29tLzE
Started GET "/rooms/1/messages/new" for 153.205.220.93 at 2022-10-19 13:09:44 +0000
Cannot render console from 153.205.220.93! Allowed networks: 127.0.0.0/127.255.255.255, ::1
Processing by MessagesController#new as HTML
  Parameters: {"room_id"=>"1"}
  Room Load (0.1ms)  SELECT "rooms".* FROM "rooms" WHERE "rooms"."id" = ? LIMIT ?  [["id", 1], ["LIMIT", 1]]
  ↳ app/controllers/messages_controller.rb:19:in `set_room'
  Rendering messages/new.html.erb
  Rendered messages/new.html.erb (Duration: 0.8ms | Allocations: 422)
Completed 200 OK in 3ms (Views: 1.3ms | ActiveRecord: 0.1ms | Allocations: 1245)


Started GET "/cable" for 153.205.220.93 at 2022-10-19 13:09:44 +0000
Cannot render console from 153.205.220.93! Allowed networks: 127.0.0.0/127.255.255.255, ::1
Started GET "/cable/" [WebSocket] for 153.205.220.93 at 2022-10-19 13:09:44 +0000
Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket)
Turbo::StreamsChannel is transmitting the subscription confirmation
Turbo::StreamsChannel is streaming from Z2lkOi8vY2hhdC9Sb29tLzE

After reloading

The same result as "just after running bin/rails server".

JRuby

$ ruby -v
jruby 9.3.7.0 (2.6.8) 2022-08-16 c79ef237e0 OpenJDK 64-Bit Server VM 17.0.4+8-Debian-1deb11u1 on 17.0.4+8-Debian-1deb11u1 +jit [x86_64-linux]

Just after running bin/rails server

Screen Shot 2022-10-19 at 21 56 51

Started GET "/rooms/1" for 153.205.220.93 at 2022-10-19 12:56:29 +0000
Cannot render console from 153.205.220.93! Allowed networks: 127.0.0.0/127.255.255.255, ::1
   (8.8ms)  SELECT sqlite_version(*)
   (0.5ms)  SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
Processing by RoomsController#show as HTML
  Parameters: {"id"=>"1"}
  Room Load (36.7ms)  SELECT "rooms".* FROM "rooms" WHERE "rooms"."id" = ? LIMIT ?  [["id", 1], ["LIMIT", 1]]
  ↳ app/controllers/rooms_controller.rb:35:in `set_room'
  Rendering layout layouts/application.html.erb
  Rendering rooms/show.html.erb within layouts/application
  Rendered rooms/_room.html.erb (Duration: 2.5ms | Allocations: 0)
  Message Load (5.3ms)  SELECT "messages".* FROM "messages" WHERE "messages"."room_id" = ?  [["room_id", 1]]
  ↳ app/views/rooms/show.html.erb:15
  Rendered collection of messages/_message.html.erb [5 times] (Duration: 40.5ms | Allocations: 0)
  Rendered rooms/show.html.erb within layouts/application (Duration: 511.6ms | Allocations: 0)
  Rendered layout layouts/application.html.erb (Duration: 2035.7ms | Allocations: 0)
Completed 200 OK in 2371ms (Views: 2066.2ms | ActiveRecord: 51.3ms | Allocations: 0)


Started GET "/rooms/1/messages/new" for 153.205.220.93 at 2022-10-19 12:56:32 +0000
Cannot render console from 153.205.220.93! Allowed networks: 127.0.0.0/127.255.255.255, ::1
Started GET "/cable" for 153.205.220.93 at 2022-10-19 12:56:32 +0000
Cannot render console from 153.205.220.93! Allowed networks: 127.0.0.0/127.255.255.255, ::1
Started GET "/cable/" [WebSocket] for 153.205.220.93 at 2022-10-19 12:56:32 +0000
Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket)
Processing by MessagesController#new as HTML
  Parameters: {"room_id"=>"1"}
  Room Load (5.9ms)  SELECT "rooms".* FROM "rooms" WHERE "rooms"."id" = ? LIMIT ?  [["id", 1], ["LIMIT", 1]]
  ↳ app/controllers/messages_controller.rb:19:in `set_room'
  Rendering messages/new.html.erb
Turbo::StreamsChannel is transmitting the subscription confirmation
Turbo::StreamsChannel is streaming from Z2lkOi8vY2hhdC9Sb29tLzE
  Rendered messages/new.html.erb (Duration: 61.7ms | Allocations: 0)
Completed 200 OK in 227ms (Views: 91.9ms | ActiveRecord: 5.9ms | Allocations: 0)

After reloading

Screen Shot 2022-10-19 at 21 58 00

Started GET "/rooms/1" for 153.205.220.93 at 2022-10-19 12:57:00 +0000
Cannot render console from 153.205.220.93! Allowed networks: 127.0.0.0/127.255.255.255, ::1
Processing by RoomsController#show as HTML
  Parameters: {"id"=>"1"}
  Room Load (0.7ms)  SELECT "rooms".* FROM "rooms" WHERE "rooms"."id" = ? LIMIT ?  [["id", 1], ["LIMIT", 1]]
  ↳ app/controllers/rooms_controller.rb:35:in `set_room'
  Rendering layout layouts/application.html.erb
  Rendering rooms/show.html.erb within layouts/application
  Rendered rooms/_room.html.erb (Duration: 2.5ms | Allocations: 0)
  Message Load (0.7ms)  SELECT "messages".* FROM "messages" WHERE "messages"."room_id" = ?  [["room_id", 1]]
  ↳ app/views/rooms/show.html.erb:15
  Rendered collection of messages/_message.html.erb [5 times] (Duration: 22.5ms | Allocations: 0)
  Rendered rooms/show.html.erb within layouts/application (Duration: 111.8ms | Allocations: 0)
  Rendered layout layouts/application.html.erb (Duration: 219.4ms | Allocations: 0)
Completed 200 OK in 260ms (Views: 233.5ms | ActiveRecord: 1.4ms | Allocations: 0)


Finished "/cable/" [WebSocket] for 153.205.220.93 at 2022-10-19 12:57:00 +0000
Started GET "/rooms/1/messages/new" for 153.205.220.93 at 2022-10-19 12:57:00 +0000
Cannot render console from 153.205.220.93! Allowed networks: 127.0.0.0/127.255.255.255, ::1
Processing by MessagesController#new as HTML
  Parameters: {"room_id"=>"1"}
Started GET "/cable" for 153.205.220.93 at 2022-10-19 12:57:00 +0000
Cannot render console from 153.205.220.93! Allowed networks: 127.0.0.0/127.255.255.255, ::1
  Room Load (12.9ms)  SELECT "rooms".* FROM "rooms" WHERE "rooms"."id" = ? LIMIT ?  [["id", 1], ["LIMIT", 1]]
  ↳ app/controllers/messages_controller.rb:19:in `set_room'
Started GET "/cable/" [WebSocket] for 153.205.220.93 at 2022-10-19 12:57:01 +0000
Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket)
  Rendering messages/new.html.erb
  Rendered messages/new.html.erb (Duration: 31.1ms | Allocations: 0)
Completed 200 OK in 144ms (Views: 57.0ms | ActiveRecord: 12.9ms | Allocations: 0)


Started GET "/cable" for 153.205.220.93 at 2022-10-19 12:57:07 +0000
Cannot render console from 153.205.220.93! Allowed networks: 127.0.0.0/127.255.255.255, ::1
Started GET "/cable/" [WebSocket] for 153.205.220.93 at 2022-10-19 12:57:07 +0000
Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket)
Started GET "/cable" for 153.205.220.93 at 2022-10-19 12:57:16 +0000
Cannot render console from 153.205.220.93! Allowed networks: 127.0.0.0/127.255.255.255, ::1
Started GET "/cable/" [WebSocket] for 153.205.220.93 at 2022-10-19 12:57:16 +0000
Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket)
Started GET "/cable" for 153.205.220.93 at 2022-10-19 12:57:23 +0000
Cannot render console from 153.205.220.93! Allowed networks: 127.0.0.0/127.255.255.255, ::1
Started GET "/cable/" [WebSocket] for 153.205.220.93 at 2022-10-19 12:57:23 +0000
Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket)
Started GET "/cable" for 153.205.220.93 at 2022-10-19 12:57:31 +0000
Cannot render console from 153.205.220.93! Allowed networks: 127.0.0.0/127.255.255.255, ::1
Started GET "/cable/" [WebSocket] for 153.205.220.93 at 2022-10-19 12:57:31 +0000
Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket)
Started GET "/cable" for 153.205.220.93 at 2022-10-19 12:57:40 +0000
Cannot render console from 153.205.220.93! Allowed networks: 127.0.0.0/127.255.255.255, ::1
Started GET "/cable/" [WebSocket] for 153.205.220.93 at 2022-10-19 12:57:40 +0000
Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket)
Started GET "/cable" for 153.205.220.93 at 2022-10-19 12:57:50 +0000
Cannot render console from 153.205.220.93! Allowed networks: 127.0.0.0/127.255.255.255, ::1
Started GET "/cable/" [WebSocket] for 153.205.220.93 at 2022-10-19 12:57:50 +0000
Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket)
Started GET "/cable" for 153.205.220.93 at 2022-10-19 12:58:00 +0000
Cannot render console from 153.205.220.93! Allowed networks: 127.0.0.0/127.255.255.255, ::1
Started GET "/cable/" [WebSocket] for 153.205.220.93 at 2022-10-19 12:58:00 +0000
Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket)

@wojja
Copy link

wojja commented Apr 19, 2023

I am seeing the issue with Puma on JRuby. ActionCable works directly after starting Puma and stops working after the first reload. The same Rails app workes fine with Passenger on CRuby.

$ bundle exec puma --version
puma version 6.2.2

$ ruby --version
jruby 9.4.2.0 (3.1.0) 2023-04-13 90d2913fda OpenJDK 64-Bit Server VM 17.0.6+10-LTS on 17.0.6+10-LTS +jit [x86_64-linux]

$ rails --version
Rails 6.1.7.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants