From 95ff97e2e0b0999a715f15e4250d67dc46d05ecd Mon Sep 17 00:00:00 2001 From: Carl Csaposs Date: Wed, 1 May 2024 15:56:06 +0200 Subject: [PATCH] Check if `_can_service_start` before acquiring lock --- lib/charms/opensearch/v0/opensearch_base_charm.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/charms/opensearch/v0/opensearch_base_charm.py b/lib/charms/opensearch/v0/opensearch_base_charm.py index 56081f80d..c2697e87e 100644 --- a/lib/charms/opensearch/v0/opensearch_base_charm.py +++ b/lib/charms/opensearch/v0/opensearch_base_charm.py @@ -810,6 +810,10 @@ def _handle_change_to_main_orchestrator_if_needed( def _start_opensearch(self, event: _StartOpenSearch) -> None: # noqa: C901 """Start OpenSearch, with a generated or passed conf, if all resources configured.""" + if not self._can_service_start(): + self.node_lock.release() + event.defer() + return if not self.node_lock.acquired: # (Attempt to acquire lock even if `event.ignore_lock`) if event.ignore_lock: @@ -827,11 +831,6 @@ def _start_opensearch(self, event: _StartOpenSearch) -> None: # noqa: C901 event.defer() return - if not self._can_service_start(): - self.node_lock.release() - event.defer() - return - if self.opensearch.is_failed(): self.node_lock.release() self.status.set(BlockedStatus(ServiceStartError))