-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add settings change notifier #8813
Add settings change notifier #8813
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a race condition in DefaultSettingsChangeBroker
.
for (subscriber in subscribers) { | ||
subscriber.receive() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This accesses subscribers
without synchronizing on lock
. If a subscriber is removed in one thread while this is iterating over subscribers in another thread, a ConcurrentModificationException
could be thrown.
The problem can be avoided by also wrapping this method body in synchronized(lock) { … }
or by using CopyOnWriteArraySet
which can be used without any manual locking/synchronization.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I avoided synchronizing this method to balance performance with the low likelihood of concurrent modifications in our use case. However, I agree that the current approach is not robust and should be replaced with a more comprehensive solution in the future.
The CopyOnWriteArraySet
is a Java only dependency and I opted for a Kotlin specific alternative.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a lock around the receivers to avoid ConcurrentModificationException
legacy/preferences/src/main/java/app/k9mail/legacy/preferences/DefaultSettingsChangeBroker.kt
Show resolved
Hide resolved
legacy/core/src/main/java/com/fsck/k9/preferences/RealDrawerConfigManager.kt
Show resolved
Hide resolved
…r changed settings updates
1258b94
to
84c7678
Compare
This introduces a new settings change notification system to the project. The main changes include adding a publish/subscribe pattern with a broker and publisher for settings changes, updating existing classes to use this new system, and adding tests for the new functionality.
The drawer is now immediatelly updated whenever a setting is changed.
Resolves #8765