-
Notifications
You must be signed in to change notification settings - Fork 905
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
LiveView + Caddy does not handle server restarts gracefully #2544
Comments
The fix may be the code block proposed in this comment: |
Some more digging today:
I can't think of a good solution on the LiveView side for handling this ambiguity, unfortunately. Stuck between a rock in a hard place. For our own app, we will explore switching to nginx to work around this issue. Separate from this issue, we were considering doing this anyway since Caddy does not support graceful config reloads for websockets, impacting our blue-green deployment strategy, as it will close all active websocket connections everytime the config changes. See caddyserver/caddy#3143 . |
I'm also running into this issue, which unfortunately happens whenever Caddy's config is updated/reloaded. It results in the UI showing an Internet Disconnected error, but the livesocket debug doesn't show a disconnected event. It only shows the liveview being destroyed. If it's the 1001 code that's the issue, is there something else we could compare against or check to see if we're actually navigating away? |
This should be fixed by 953a862. |
Environment
Elixir 1.14.3 (compiled with Erlang/OTP 25)
Actual behavior
This bug has the same root cause as #2421 .
caddy reload --force
or similarHere is a simple way to repo this:
caddy reverse-proxy --from :4001 --to :4000
caddy reverse-proxy
processExpected behavior
The websocket connection should be established.
Root cause
This is because when Caddy goes down or reloads/restarts, it closes all websocket connections with a status code of 1001.
https://github.com/caddyserver/caddy/blob/90798f3eea6b7a219a9bb55f680919c0504263e3/modules/caddyhttp/reverseproxy/streaming.go#L254
This results in the the web client JS code to unload and no longer retry to re-establish a connection.
https://github.com/phoenixframework/phoenix_live_view/blob/main/assets/js/phoenix_live_view/live_socket.js#L504-L509
This issue was hit previously by Bandit in #2421 , and the solution there was for Bandit to return 1000 in conformance with how Cowboy works - but I don't think that is a correct solution to the root cause.
I don't view Caddy returning 1001 in this scenario to be incorrect. Per the RFC:
Caddy is indeed closing the connection to "go down" in this scenario, so 1001 seems like a reasonable code to give.
The text was updated successfully, but these errors were encountered: