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

Fix CTRL_CLOSE, CTRL_LOGOFF and CTRL_SHUTDOWN on windows #7122

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Finomnis
Copy link
Contributor

Fixes #7039.

Motivation

According to https://learn.microsoft.com/en-us/windows/console/handlerroutine#remarks, the windows signals CTRL_CLOSE, CTRL_LOGOFF and CTRL_SHUTDOWN immediately kill the process upon being handled.

The intention is that the handler of those signals performs cleanup tasks, and once completed, it returns and the process is killed.

This behavior is sadly not really compatible with an async system that is based on signals.

Solution

There are multiple possible ways to solve this; the easiest one being to simply never return from the handler thread. This works because Rust calls ExitProcess after its main (to my knowledge). I tested it on a project of mine, and it seems to work indeed.

@Finomnis Finomnis force-pushed the fix_windows_signals branch from 77cf12e to 6e60886 Compare January 25, 2025 05:22
@Finomnis Finomnis force-pushed the fix_windows_signals branch from 6e60886 to 44a84f2 Compare January 25, 2025 05:25
@maminrayej maminrayej added A-tokio Area: The main tokio crate M-signal Module: tokio/signal labels Jan 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate M-signal Module: tokio/signal
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tokio::signals::windows - are windows signals correctly handled?
2 participants