Open leoMehlig opened 5 months ago
Which Defaults
version? And which observation methods?
@sindresorhus We are using 7.3 in the latest production, and use the Defaults.publisher(keys:)
and Defaults.updates
methods.
All crashes happen on a background queue, which might suggest it is some concurrency issue. UserDefaults is thread safe, but maybe KVO isn't?
The crash happens in Apple's code that notifies about KVO, not the code that subscribes to KVO, so this really seems like UserDefaults itself is accidentally not fully thread-safe.
Without a way to reproduce the issue locally, I cannot really come up with a workaround. Defaults cannot wrap calls to UserDefaulta in DispatchQueue.main.async
as it can cause synchronization issues (for example, if the value is read right after setting it).
I also have not seen this kind of crash in any of my 40 apps (almost all of them use Defaults
).
You could try this: https://github.com/sindresorhus/Defaults/commit/eef0df09305106ff18ba9d575c1144d3c886c62d But it could cause problems if the value is read right after.
Thanks a lot. I've moved to this branch and will report bck after the next update.
Since using this library, we are seeing some crash reports which look related to KVO and UserDefaults. We haven't been able to reproduce them but are seeing crash reports on all iOS versions (although more on iOS 15).
Has anyone seen something similar or any pointers on how to fix this (happy to submit a PR)?
Here are some ideas/observations/infos: