Skip to content

Commit c3faa67

Browse files
committed
Document store close method as optional and call if it exists
1 parent bbb6237 commit c3faa67

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

ldclient/impl/datasystem/fdv2.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,15 +232,14 @@ def is_monitoring_enabled(self) -> bool:
232232
def close(self):
233233
"""
234234
Close the wrapper and stop the repeating task poller if it's running.
235-
This is called by Store.close() during shutdown to ensure the poller thread is stopped.
235+
Also forwards the close call to the underlying store if it has a close method.
236236
"""
237-
poller_to_stop = None
238237
with self.__lock.write():
239-
poller_to_stop = self.__poller
240-
self.__poller = None
241-
242-
if poller_to_stop is not None:
243-
poller_to_stop.stop()
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()
244243

245244

246245
class FDv2(DataSystem):

ldclient/interfaces.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,28 @@ def initialized(self) -> bool:
189189
# :return: true if the underlying data store is reachable
190190
# """
191191

192+
# WARN: This isn't a required method on a FeatureStore. The SDK will
193+
# check if the provided store responds to this method, and if it does,
194+
# will call it during shutdown to release any resources (such as database
195+
# connections or connection pools) that the store may be using.
196+
#
197+
# @abstractmethod
198+
# def close(self):
199+
# """
200+
# Releases any resources used by the data store implementation.
201+
#
202+
# This method will be called by the SDK during shutdown to ensure proper
203+
# cleanup of resources such as database connections, connection pools,
204+
# network sockets, or other resources that should be explicitly released.
205+
#
206+
# Implementations should be idempotent - calling close() multiple times
207+
# should be safe and have no additional effect after the first call.
208+
#
209+
# This is particularly important for persistent data stores that maintain
210+
# connection pools or other long-lived resources that should be properly
211+
# cleaned up when the SDK is shut down.
212+
# """
213+
192214

193215
class FeatureStoreCore:
194216
"""

0 commit comments

Comments
 (0)