From 20b1aaff9bb0e5fe8682c9c9630f2f34ec8b9086 Mon Sep 17 00:00:00 2001
From: Hideo Yamauchi <renayama19661014@ybb.ne.jp>
Date: Mon, 2 Dec 2024 16:26:42 +0900
Subject: [PATCH 1/2] Mid: systemd: Fix when monitor of systemd resource
 continues to be pending.

---
 daemons/execd/execd_commands.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/daemons/execd/execd_commands.c b/daemons/execd/execd_commands.c
index 5356c5cc97..8ade0ac345 100644
--- a/daemons/execd/execd_commands.c
+++ b/daemons/execd/execd_commands.c
@@ -903,6 +903,27 @@ action_complete(svc_action_t * action)
                     }
                 }
             }
+        } else if (pcmk__str_any_of(cmd->action, PCMK_ACTION_MONITOR, PCMK_ACTION_STATUS, NULL) && 
+                  (cmd->interval_ms > 0)) { 
+            /* For monitors, excluding follow-up monitors,                                  */
+            /* if the pending state persists from the first notification until its timeout, */
+            /* it will be treated as a timeout.                                             */
+
+            if ((cmd->result.execution_status == PCMK_EXEC_PENDING) &&
+                (cmd->last_notify_op_status == PCMK_EXEC_PENDING)) {
+                int time_left = time(NULL) - (cmd->epoch_rcchange + (cmd->timeout_orig/1000));
+
+                if (time_left >= 0) {
+                    crm_notice("Giving up on %s %s (rc=%d): monitor pending timeout (first pending notification=%s timeout=%ds)",
+                        cmd->rsc_id, cmd->action,
+                        cmd->result.exit_status, pcmk__trim(ctime(&cmd->epoch_rcchange)), cmd->timeout_orig);
+                    pcmk__set_result(&(cmd->result), PCMK_OCF_UNKNOWN_ERROR,
+                         PCMK_EXEC_TIMEOUT,
+                         "Investigate reason for timeout, and adjust "
+                         "configured operation timeout if necessary");
+                    cmd_original_times(cmd);
+                }
+            }
         }
     }
 #endif
-- 
2.43.0

