Skip to content
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

Shutdown the server if any of the tasks crashes #3672

Merged
merged 1 commit into from
Dec 17, 2024

Conversation

sandhose
Copy link
Member

This is to avoid to be in a state where the activity tracker, the task worker or the listener crashed, but the app is still running.

This works by having each task have a drop guard on a cancellation token, meaning that if the task is being dropped, the cancellation token is cancelled, which will cause other tasks to stop as well.
If the service is stopeed that way, it will also use a failure exit code to indicate that the service has been stopped unexpectedly.

Fixes #2625

Copy link

cloudflare-workers-and-pages bot commented Dec 13, 2024

Deploying matrix-authentication-service-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 657b3de
Status: ✅  Deploy successful!
Preview URL: https://80b9feee.matrix-authentication-service-docs.pages.dev
Branch Preview URL: https://quenting-shutdown-on-crash.matrix-authentication-service-docs.pages.dev

View logs

@sandhose sandhose requested a review from reivilibre December 13, 2024 09:23
@sandhose sandhose force-pushed the quenting/shutdown-on-crash branch from 990b992 to 414fe21 Compare December 13, 2024 09:24
if likely_crashed {
ExitCode::FAILURE
} else {
ExitCode::SUCCESS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that's orthogonal to this PR, but is exiting with SUCCESS really the right thing to do if exiting due to a SIGTERM or so?

It's possible the SIGTERM was sent by another process due to an out of memory situation or something like that, but then a successful exit code doesn't necessarily trigger a restart in e.g. systemd by default. (I've had this failure mode with other services in the past.)

I mostly just wonder what the convention is for this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm SIGTERM is usually sent when asking for a graceful shutdown. Docker/Kubernetes does that, systemd probably as well

@sandhose sandhose enabled auto-merge (squash) December 17, 2024 07:28
@sandhose sandhose force-pushed the quenting/shutdown-on-crash branch from 0bbc59a to c66f37f Compare December 17, 2024 08:43
@sandhose sandhose force-pushed the quenting/shutdown-on-crash branch from c66f37f to 657b3de Compare December 17, 2024 09:04
@sandhose sandhose merged commit 88fb4ed into main Dec 17, 2024
19 checks passed
@sandhose sandhose deleted the quenting/shutdown-on-crash branch December 17, 2024 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Losing the connection to Postgres stops the background jobs
2 participants