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)