open-feature / python-sdk

Python SDK for OpenFeature
https://openfeature.dev
Apache License 2.0
43 stars 16 forks source link

Review thread safety of client/API/Evaluation context #96

Open toddbaert opened 1 year ago

toddbaert commented 1 year ago

Review the thread safety of the SDK to make sure there's no potential concurrency issues, particularly around state maintained in the global API object, clients, and evaluation context objects.

See here for a similar discussion in the Java SDK and others.

Definition of done:

toddbaert commented 1 year ago

@matthewelwell @hlipsig @tcarrio do we need to worry about locking/concurrency here? I know there's a threading module in Python. Are any locks necessary, especially around global state? From our meeting if sounds like this might not be necessary, but I have limited Python experience and can't say...

beeme1mr commented 9 months ago

Hey @federicobond perhaps you could answer this question. Do we need to be concerned about threading issues?

federicobond commented 9 months ago

I'd have to take a closer look at it. The GIL has us covered in some cases for simple assignments but anything more complex than that should probably be guarded by a lock.

add_hooks is probably not thread-safe due to read-update-write race conditions when concatenating lists.

set_provider used to be thread safe but likely isn't now with the new shutdown and initialize logic.