Fix stuck systemctl poweroff could block terminate#40866
Open
chemwolf6922 wants to merge 5 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adjusts the Linux-side instance termination path in systemd mode so that a potentially-blocking systemctl poweroff invocation cannot prevent the termination timeout/fallback (reboot(RB_POWER_OFF)) from being reached.
Changes:
- Run
systemctl poweroffon a detached thread to avoid blockingwsl --terminatewhensystemctlhangs. - Always start the existing
BootInitTimeout-based fallback timer on the main path and forcereboot(RB_POWER_OFF)on timeout.
benhillis
reviewed
Jun 22, 2026
| { | ||
| std::this_thread::sleep_for(std::chrono::milliseconds(Config.BootInitTimeout)); | ||
| LOG_ERROR("systemctl poweroff did not terminate the instance in {} ms, calling reboot(RB_POWER_OFF)", Config.BootInitTimeout); | ||
| std::thread([]() { |
Member
There was a problem hiding this comment.
Instead of a local std::thread(...).detach(), use the existing UtilCreateChildProcess helper. This will simplify the code.
if (Config.BootInit && !Config.BootStartWriteSocket)
{
THROW_LAST_ERROR_IF(UtilSetSignalHandlers(g_SavedSignalActions, false) < 0);
//
// systemctl poweroff is normally async but can block in rare cases. Run it in a
// child process so a stuck invocation can't prevent the fallback timeout below.
//
UtilCreateChildProcess("poweroff", []() {
if (UtilExecCommandLine("systemctl poweroff", nullptr) < 0)
{
LOG_ERROR("systemctl poweroff failed, calling reboot(RB_POWER_OFF)");
reboot(RB_POWER_OFF);
}
});
std::this_thread::sleep_for(std::chrono::milliseconds(Config.BootInitTimeout));
LOG_ERROR("systemctl poweroff did not terminate the instance in {} ms, calling reboot(RB_POWER_OFF)", Config.BootInitTimeout);
}
Contributor
Author
There was a problem hiding this comment.
Do we need a new process for this?
benhillis
reviewed
Jun 22, 2026
benhillis
reviewed
Jun 22, 2026
OneBlue
reviewed
Jun 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of the Pull Request
The
systemctl poweroffcall is async after the operation is enqueued per https://man7.org/linux/man-pages/man1/systemctl.1.html. However, in some rare cases it could block. And that will block thewsl --terminatecall. For example: #40433 (comment)This PR moves the calling logic to a separate thread, so the fallback timeout is always started in the systemd path.
PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed
No new tests are added as the original failure could not be easily reproduced.