Search code examples
ruby-on-railswebsocketactioncableruby-on-rails-7

How to disable Rails ActionCable WebSocket channel for other Rails app in local env


I'm working on two different Rails apps. On App 1, I created a channel to broadcast changes called "ProductsChannel". I later shut down the server for App 1, and spun up the server for App 2 which I hadn't worked on in a couple days. But now it's trying to connect to my "ProductsChannel" from App 1. It can't find it so it tells me repeatably that it can't find the channel. Logs are below.

How do I stop App 2 from trying to use WebSockets? I've never added any channels to App 2 so not sure how it got pulled into this.

Started GET "/cable" for ::1 at 2023-09-21 14:57:20 +0200
  ActiveRecord::SchemaMigration Pluck (0.2ms)  SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
Started GET "/cable" [WebSocket] for ::1 at 2023-09-21 14:57:20 +0200
Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket)
Started GET "/cable" for ::1 at 2023-09-21 14:57:20 +0200
Started GET "/cable" [WebSocket] for ::1 at 2023-09-21 14:57:20 +0200
Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket)
Started GET "/cable" for ::1 at 2023-09-21 14:57:20 +0200
Started GET "/cable" [WebSocket] for ::1 at 2023-09-21 14:57:20 +0200
Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket)
Subscription class not found: "ProductsChannel"
Subscription class not found: "ProductsChannel"
Subscription class not found: "ProductsChannel"
...

Both apps are on Rails 7.

I've made sure App 1's server is not running. I've tried shutting down App 2 and restarting.

I suspect a laptop reboot might solve it, but I shouldn't have to reboot my whole machine every time I switch apps.


Solution

  • Since the logs of enabled application contain requests to the websockets endpoint and even contain records that it was not possible to find channel of disabled application — it means some client still has connection to your server and send these requests

    In this regard, the first thought is an open browser tab that was subscribed to the websocket channel on the same port as the current backend

    To exclude this behavior, you can either close such tabs or use different ports for different applications