From cd45bb0ec149aca17f89d44813aa942312c0c28a Mon Sep 17 00:00:00 2001 From: Carl Csaposs Date: Thu, 2 May 2024 12:11:40 +0200 Subject: [PATCH] Prevent duplicate peer-relation-changed deferred events Follow up to #266 --- lib/charms/opensearch/v0/opensearch_base_charm.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/charms/opensearch/v0/opensearch_base_charm.py b/lib/charms/opensearch/v0/opensearch_base_charm.py index c2697e87e..f7e334884 100644 --- a/lib/charms/opensearch/v0/opensearch_base_charm.py +++ b/lib/charms/opensearch/v0/opensearch_base_charm.py @@ -1286,7 +1286,13 @@ def _recompute_roles_if_needed(self, event: RelationChangedEvent): try: nodes = self._get_nodes(self.opensearch.is_node_up()) if len(nodes) < self.app.planned_units(): + if self._is_peer_rel_changed_deferred: + # We already deferred this event during this Juju event. Retry on the next + # Juju event. + return event.defer() + # If the handler is called again within this Juju hook, we will abandon the event + self._is_peer_rel_changed_deferred = True return self._compute_and_broadcast_updated_topology(nodes)