You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ruflet_rails holds one Rails executor for a WebSocket's whole life: the dev server hangs after a code edit, handlers read a stale query cache, leased DB connections are never returned #101
Ruflet::Rails.native runs the whole life of a client's WebSocket inside a single Rails.application.executor.wrap. Rails runs one executor per unit of work: an HTTP request, a job, or an ActionCable channel command. While a native client (phone, desktop, Ruflet Explorer) stays connected, three things go wrong:
In development, the server hangs after a code edit. The socket thread holds the code-reload interlock share until the client disconnects. The first HTTP request after an edit waits for the reload, the reload waits for that share, and every later request queues behind it. rails s --desktop starts a desktop client automatically, so in development a client is usually connected.
Handlers read stale rows. Active Record's query cache stays on for the whole connection. When a handler repeats a query after another process (a job worker, another Puma worker, the console) has written, it gets the cached result. This also happens in production.
Leased database connections never return to the pool. If the entrypoint or a handler leases a connection (for example with ActiveRecord::Base.connection), each connected client keeps it until it disconnects. Once as many clients are connected as the pool has connections, HTTP requests fail with ActiveRecord::ConnectionTimeoutError.
Repro
This is a minimal Rails 8.1.3.1 app in development mode (enable_reloading = true, FileUpdateChecker, SQLite). The endpoint is mounted as the README shows: match "/ws", to: Ruflet::Rails.native { |page| ... }, via: :all. A client connects and registers.
still blocked after 3 s; a second request is blocked too; both finish only when the client disconnects
Another SQLite connection inserts a row, then a click handler runs Note.count
1
0
Pool of 1; the entrypoint ran ActiveRecord::Base.connection.select_value("SELECT 1"); then an HTTP request runs Note.count
0
ActiveRecord::ConnectionTimeoutError: could not obtain a connection from the pool within 1.000 seconds
With a real Puma 7.2.1 process and a TCP WebSocket client, GET /up after an edit times out (8 s) while the client is connected. With no client connected, the same request answers in 0.01 s.
Where
packages/ruflet_rails/lib/ruflet/rails/protocol/endpoint.rb: Thread.new { rails_executor_wrap { handle_socket(...) } } and #rails_executor_wrap
packages/ruflet_rails/lib/ruflet/rails/protocol/local_server.rb: where a per-message wrap belongs (handle_message / close_connection)
Expected behavior
Each client message, and the disconnect, should be one executor run. This is how Rails handles HTTP requests, and how ActionCable wraps each channel command in app.executor.wrap (actioncable/lib/action_cable/engine.rb). The executor resets ActiveSupport::CurrentAttributes when a run completes. Today, Current.* set in the entrypoint stays set for the whole connection, so a fix must carry that state from one message to the next instead of resetting it.
Activity