Skip to content

Commit

Permalink
Fix data race in SingletonHolder<T>::hasLiveInstance
Browse files Browse the repository at this point in the history
Summary:
hasLiveInstance() accesses instance_weak_ which is not safe to access concurrently with createInstance().
In all other places hasLiveInstance() is already called while holding the vault state lock or after switching state to shutdown (which prevents concurrent creation).

livingSingletonCount() should be performing similar synchronization as well.

Reviewed By: dsesh

Differential Revision: D62614961

fbshipit-source-id: 7552e46fc12fb4e6e02c5094afb1d4a4e0b7804c
  • Loading branch information
andriigrynenko authored and facebook-github-bot committed Sep 13, 2024
1 parent c9c2b90 commit c4e5844
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions folly/Singleton.h
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ class SingletonVault {
bool eagerInitComplete() const;

size_t livingSingletonCount() const {
auto state = state_.rlock();
auto singletons = singletons_.rlock();

size_t ret = 0;
Expand Down

0 comments on commit c4e5844

Please sign in to comment.