Fix stuck systemctl poweroff could block terminate (#40866)
* Avoid stuck systemctl poweroff blocking terminate
Feng Wang committed
Jun 25, 2026 at 10:27 UTC
5a04cdef024e0387c040a05f70dfd0c334e55281
1 file changed
+8
-5
src/linux/init/init.cpp
+8
-5
@@ -2753,11 +2753,14 @@ try
2753
{
2754
THROW_LAST_ERROR_IF(UtilSetSignalHandlers(g_SavedSignalActions, false) < 0);
2755
2756
- if (UtilExecCommandLine("systemctl poweroff", nullptr) == 0)
2757
- {
2758
- std::this_thread::sleep_for(std::chrono::milliseconds(Config.BootInitTimeout));
2759
- LOG_ERROR("systemctl poweroff did not terminate the instance in {} ms, calling reboot(RB_POWER_OFF)", Config.BootInitTimeout);
2760
- }
2756
+ //
2757
+ // systemctl poweroff is normally async but can block in rare cases.
2758
+ // Run it in a thread so a stuck invocation can't prevent the fallback timeout below.
2759
+ //
2760
+ std::thread([]() { UtilExecCommandLine("systemctl poweroff", nullptr); }).detach();
2761
+
2762
+ std::this_thread::sleep_for(std::chrono::milliseconds(Config.BootInitTimeout));
2763
+ LOG_ERROR("systemctl poweroff did not terminate the instance in {} ms, calling reboot(RB_POWER_OFF)", Config.BootInitTimeout);
2764
}
2765
2766
reboot(RB_POWER_OFF);