Skip to content

Commit

Permalink
Fix check-then-act in failover.remote event subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
themylogin committed Sep 17, 2024
1 parent 79d4b32 commit e3e148b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/middlewared/middlewared/plugins/failover_/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ def connect_and_wait(self, *, legacy=False):
try:
with Client(url, reserved_ports=True) as c:
self.client = c
self.connected.set()
# Subscribe to all events on connection
with self._subscribe_lock:
self.connected.set()
# Subscribe to all events on connection
for name in self._subscriptions:
self.client.subscribe(name, partial(self._sub_callback, name))
self._on_connect()
Expand Down Expand Up @@ -162,9 +162,9 @@ def call(self, *args, **kwargs):
raise CallError(str(e), e.errno or errno.EFAULT)

def subscribe(self, name, callback):
# Only subscribe if we are already connected, otherwise simply register it
if name not in self._subscriptions and self.is_connected():
with self._subscribe_lock:
with self._subscribe_lock:
# Only subscribe if we are already connected, otherwise simply register it
if name not in self._subscriptions and self.is_connected():
self.client.subscribe(name, partial(self._sub_callback, name))
self._subscriptions[name].append(callback)

Expand Down

0 comments on commit e3e148b

Please sign in to comment.