core/sleep: set timeout for freeze/thaw operation to 1.5 seconds
authormsizanoen1 <msizanoen@qtmlabs.xyz>
Wed, 7 Dec 2022 16:22:05 +0000 (23:22 +0700)
committermsizanoen1 <msizanoen@qtmlabs.xyz>
Thu, 8 Dec 2022 11:58:00 +0000 (12:58 +0100)
A FreezeUnit operation can hang due to the presence of kernel threads
(see last 2 commits). Keeping the default configuration will mean the
system will hang for 25 seconds in suspend waiting for the response. 1.5
seconds should be sufficient for most cases.

src/sleep/sleep.c

index e74e334e3327461780871e4716635c9f5cf265cd..9b69a2a10d1fcd315c87d7bb083b2d07ec670d12 100644 (file)
@@ -366,6 +366,9 @@ static int freeze_thaw_user_slice(const char **method) {
         if (r < 0)
                 return log_debug_errno(r, "Failed to open connection to systemd: %m");
 
+        /* Wait for 1.5 seconds at maximum for freeze operation */
+        (void) sd_bus_set_method_call_timeout(bus, 1500 * USEC_PER_MSEC);
+
         r = bus_call_method(bus, bus_systemd_mgr, *method, &error, NULL, "s", SPECIAL_USER_SLICE);
         if (r < 0)
                 return log_debug_errno(r, "Failed to execute operation: %s", bus_error_message(&error, r));