-
-
Notifications
You must be signed in to change notification settings - Fork 298
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
Shutting down Mercure server takes indefinitely #986
Comments
Good catch. IMHO, we should detect that Caddy is shutting down (we may use the context for that) and cleanly close the SSE connection on our side. This should be done in the Caddy module. In the meantime, your workaround looks good and we could at least update the default config. |
As per dunglas#986, adds a default grace period of 1s. If the same global option has been set using the $GLOBAL_OPTIONS it wil override the default one.
As per dunglas#986, adds a default grace period of 1s. If the same global option has been set using the $GLOBAL_OPTIONS it wil override the default one.
Thanks for the PR @bobvandevijver. I dived into this issue, and it looks like the current behavior is "expected". When I try to reproduce locally, the server closes all connections and finally terminates:
I think that the issue you're getting is because some of your connections with the clients are "stuck", so the underlying goroutine is stuck and https://github.com/dunglas/mercure/blob/main/subscribe.go#L125 is never called. Could you show me your timeout configs (if any)? Setting Mercure's |
I am using the default Caddy file with only some configuration for the server name, transport and keys.
However, I am using a nginx proxy (based on https://mercure.rocks/docs/hub/nginx) to be able to host the hub on the same port and domain as the main Symfony application. Client IP detection doesn't work currently (but that is why I just responded to #546).
Maybe that is relevant? I can consistently reproduce the issue with a 10s timeout window, where a freshly created connection isn't dropped (also visible in the browser console) when the restart is requested. Only after 10s the |
I was looking into a very slow shutdown of the Mercure instance I am running on a Ubuntu server, using a systemd unit.
Unit file
Logs
From the logs it became clear that the default shutdown action (SIGTERM), while received perfectly fine by caddy/mercure, didn't really do anything except for denying new connections. After a 90 seconds, systemd would have had enough, and use SIGKILL to get rid of the process.
One line caught my attention:
This is something that is described in the Caddy manual under the
grace_period
option and allows the clients to complete their request before the server is actually shutdown. However, with SSE and long running connections, this does not really make sense as those clients will keep the connection option.I have now added an additional env variable to my configuration:
And immediately mercure shutdowns fast, although with some errors in the log:
Logs with 1s `grace_period`
As I did not find any note about this in the documentation, I am wondering what the best course of action is. Is this be something that should only be added to the documentation, or is this maybe even something that we can can configure by default in the
Caddyfile
that is bundled with thetar.gz
releases?The text was updated successfully, but these errors were encountered: