Skip to content

Commit e876d4b

Browse files
committed
Not all stores implement close so we need to track if it has been closed
1 parent b454f38 commit e876d4b

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

ldclient/impl/datasystem/fdv2.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ def __init__(self, store: FeatureStore, store_update_sink: DataStoreStatusProvid
130130
self.__lock = ReadWriteLock()
131131
self.__last_available = True
132132
self.__poller: Optional[RepeatingTask] = None
133+
self.__closed = False
133134

134135
def init(self, all_data: Mapping[VersionedDataKind, Mapping[str, Dict[Any, Any]]]):
135136
return self.__wrapper(lambda: self.store.init(_FeatureStoreDataSetSorter.sort_all_collections(all_data)))
@@ -164,6 +165,8 @@ def __update_availability(self, available: bool):
164165
task_to_start = None
165166

166167
with self.__lock.write():
168+
if self.__closed:
169+
return
167170
if available == self.__last_available:
168171
return
169172

@@ -234,12 +237,20 @@ def close(self):
234237
Close the wrapper and stop the repeating task poller if it's running.
235238
Also forwards the close call to the underlying store if it has a close method.
236239
"""
240+
poller_to_stop = None
241+
237242
with self.__lock.write():
238-
if self.__poller is not None:
239-
self.__poller.stop()
240-
self.__poller = None
241-
if hasattr(self.store, "close"):
242-
self.store.close()
243+
if self.__closed:
244+
return
245+
self.__closed = True
246+
poller_to_stop = self.__poller
247+
self.__poller = None
248+
249+
if poller_to_stop is not None:
250+
poller_to_stop.stop()
251+
252+
if hasattr(self.store, "close"):
253+
self.store.close()
243254

244255

245256
class FDv2(DataSystem):

0 commit comments

Comments
 (0)