From be871aab47630587c911f006d1c54b1a1c7e4b4d Mon Sep 17 00:00:00 2001 From: Mateusz Poliwczak Date: Mon, 25 Aug 2025 12:04:49 +0200 Subject: [PATCH] Always sleep while restarting The /services/server/control/restart endpoint does not stop the API immediately. As a result, a login() call may still succeed just before the restart takes effect. This change introduces an additional sleep to prevent a burst of requests from reaching the server while it is in the process of restarting. --- splunklib/client.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/splunklib/client.py b/splunklib/client.py index 72cefc262..0707ede38 100644 --- a/splunklib/client.py +++ b/splunklib/client.py @@ -618,7 +618,15 @@ def restart(self, timeout=None): while datetime.now() - start < diff: try: self.login() - if not self.restart_required: + if self.restart_required: + # Prevent a burst of requests from bombarding Splunk. + # Splunk does not stop the API immediately when /services/server/control/restart + # responds, thus the login call (above) will still succeed until the server + # is actually stopped. Based on the presence of restart_required message, + # that we have added before calling restart, we know that the server did not stop yet. + sleep(1) + continue + else: return result except Exception as e: sleep(1)