Repository navigation
Description
Summary
When an event handler raises under ruflet_rails, the client gets session_crashed and the WebSocket is closed. The same app under ruflet run logs the error and keeps the session going.
ruflet_rails hosts its sessions in Ruflet::Rails::Protocol::LocalServer, which includes Ruflet::ConnectionProtocol. ConnectionProtocol#handle_message does not rescue errors per message, while Ruflet::Server#handle_message does. So the handler's exception reaches ConnectionProtocol#run_connection, which:
- logs it (
RUFLET CRASH: ...in the Rails log), - sends
session_crashed, so the client shows its error screen, - closes the socket.
The client then reconnects and registers again. The app block runs from scratch, and everything the session held is lost.
This happens on main (dd924eb) and in the published gems: connection_protocol.rb, local_server.rb and endpoint.rb are identical at v0.0.23.
Minimal repro
Any handler that raises once is enough. For example, a Form validator that raises, or this button:
clicks = 0
app = lambda do |page|
page.add(Ruflet.button(content: "Save", on_click: lambda { |_e|
clicks += 1
raise ArgumentError, "validation failed" if clicks == 1
}))
endRun it through each receiver. Register, then send the same control_event click twice:
Ruflet::Server(whatruflet runuses)Ruflet::Rails::Protocol::LocalServer, through the Rack-hijackEndpoint(whatruflet_railsuses)
Result over real socket pairs with masked WebSocket frames, the same bytes the Flutter client sends:
[ruflet run ] clicks: 2, after_first: [], after_second: ["patch_control(count=1)"], socket_eof_after_clicks: false,
log: "[embedded server] handle_message error: ArgumentError: validation failed"
[ruflet_rails ] clicks: 1, after_first: ["session_crashed(validation failed)"], after_second: [], socket_eof_after_clicks: true,
log: "server error: ArgumentError: validation failed"
Expected
The handler error is logged, and the connection and session stay up, the same as under ruflet run. ConnectionProtocol describes itself as "one connection loop shared by every server". Ruflet::Server#handle_message rescues per-message errors with this comment: "A per-message handler error ... must not tear down the whole WebSocket connection ... Log it and keep the session alive". Commit 035df8d added that rescue as a fix to the standalone server, but it never reached ConnectionProtocol.
Actual
Under ruflet_rails, one raising handler sends session_crashed, closes the socket and forces a reconnect that re-runs the app. Clicks after the first never reach their handler on that connection.
Code location
packages/ruflet_server/lib/ruflet/server/connection_protocol.rb:run_connection(lines 57-70),handle_message(lines 84-107) andon_control_event. Nothing rescues aroundpage.dispatch_event.- For comparison,
packages/ruflet_server/lib/ruflet/server.rblines 583-591 (Server#handle_messagerescue).
Errors while registering the app (the app block raising on register) should still send session_crashed, as they do today on both receivers. Protocol errors (unknown action, undecodable frame, event before register) are a separate case.
Activity