Skip to content

Commit 549dffa

Browse files
committed
[sdk-1710] ensure we always release the lock.
1 parent 5c5dcd5 commit 549dffa

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

ldclient/impl/datasystem/fdv2.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -175,20 +175,21 @@ def __update_availability(self, available: bool):
175175
task_to_start = None
176176

177177
self.__lock.lock()
178-
if available == self.__last_available:
179-
self.__lock.unlock()
180-
return
178+
try:
179+
if available == self.__last_available:
180+
return
181181

182-
state_changed = True
183-
self.__last_available = available
182+
state_changed = True
183+
self.__last_available = available
184184

185-
if available:
186-
poller_to_stop = self.__poller
187-
self.__poller = None
188-
elif self.__poller is None:
189-
task_to_start = RepeatingTask("ldclient.check-availability", 0.5, 0, self.__check_availability)
190-
self.__poller = task_to_start
191-
self.__lock.unlock()
185+
if available:
186+
poller_to_stop = self.__poller
187+
self.__poller = None
188+
elif self.__poller is None:
189+
task_to_start = RepeatingTask("ldclient.check-availability", 0.5, 0, self.__check_availability)
190+
self.__poller = task_to_start
191+
finally:
192+
self.__lock.unlock()
192193

193194
if available:
194195
log.warning("Persistent store is available again")

0 commit comments

Comments
 (0)