Skip to content

Commit

Permalink
Prevent duplicate peer-relation-changed deferred events
Browse files Browse the repository at this point in the history
Follow up to #266
  • Loading branch information
carlcsaposs-canonical committed May 2, 2024
1 parent 3012f35 commit cd45bb0
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/charms/opensearch/v0/opensearch_base_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit cd45bb0

Please sign in to comment.