Skip to content
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

Kingfisher 5.7.0 crashes #1233

Closed
3 tasks done
pepejeria opened this issue Jul 15, 2019 · 3 comments · Fixed by #1255
Closed
3 tasks done

Kingfisher 5.7.0 crashes #1233

pepejeria opened this issue Jul 15, 2019 · 3 comments · Fixed by #1255

Comments

@pepejeria
Copy link

pepejeria commented Jul 15, 2019

Check List

Thanks for considering to open an issue. Before you submit your issue, please confirm these boxes are checked.

Issue Description

I haven't seen this crash before, so I will assume that this is caused by the latest version of Kingfisher.

What

I been receiving these reports from Crashlytics

Crash log

Crashed: com.apple.root.user-initiated-qos
0  libswiftCore.dylib             0x1d144c584 swift_isUniquelyReferenced_nonNull_native + 10
1  Kingfisher                     0x1036c7728 specialized Set._Variant.remove(_:) (<compiler-generated>)
2  Kingfisher                     0x103707060 specialized thunk for @escaping @callee_guaranteed (@guaranteed MemoryStorage.Backend<A>, @guaranteed MemoryStorage.StorageObject<A>) -> () (<compiler-generated>)
3  Kingfisher                     0x1036a6f2c specialized closure #1 in Delegate.delegate<A>(on:block:) + 39 (Delegate.swift:39)
4  Kingfisher                     0x103707aec partial apply for specialized  (<compiler-generated>)
5  Kingfisher                     0x1036a7358 Delegate.call(_:) + 44 (Delegate.swift:44)
6  Kingfisher                     0x103707908 specialized MemoryStorage.Backend.CacheDelegate.cache(_:willEvictObject:) + 168 (MemoryStorage.swift:168)
7  Kingfisher                     0x103705d3c @objc MemoryStorage.Backend.CacheDelegate.cache(_:willEvictObject:) (<compiler-generated>)
8  CoreFoundation                 0x1a2d12418 __NSCacheCallDelegateWillEvictObjectCallbackWithValue + 84
9  ???                            0x56a901a2d11e50 (Missing)
10 ???                            0xca301a265d2f4 (Missing)
11 ???                            0x433181a265b3c4 (Missing)
12 ???                            0x104e81a265cd38 (Missing)
13 ???                            0x24001a265d088 (Missing)
14 ???                            0x171081a265cef8 (Missing)
15 ???                            0x344e01a26e0304 (Missing)
16 ???                            0x63a381a26e1884 (Missing)
17 ???                            0x466881a26f0998 (Missing)
18 ???                            0x73d01a26f10f0 (Missing)
19 ???                            0x73c81a28dcb38 (Missing)
20 ???                            0x75b481a28e2dc4 (Missing)
@zdo
Copy link

zdo commented Jul 31, 2019

I got the same crash too.

# OS Version: 12.3.1 (16F203)
# Device: iPhone 6s
# RAM Free: 3.9%
# Disk Free: 31.5%

Crashed: com.apple.main-thread
0  Application                    0x1021a4124 specialized Set._Variant.remove(_:) (<compiler-generated>)
1  Application                    0x1024490d4 specialized thunk for @escaping @callee_guaranteed (@guaranteed MemoryStorage.Backend<A>, @guaranteed MemoryStorage.StorageObject<A>) -> () (<compiler-generated>)
2  Application                    0x1023f89f4 specialized closure #1 in Delegate.delegate<A>(on:block:) (<compiler-generated>)
3  Application                    0x1024497b4 partial apply for specialized  (<compiler-generated>)
4  Application                    0x1023f8e20 Delegate.call(_:) (<compiler-generated>)
5  Application                    0x1024495d0 specialized MemoryStorage.Backend.CacheDelegate.cache(_:willEvictObject:) + 172 (MemoryStorage.swift:172)
6  Application                    0x1024483dc @objc MemoryStorage.Backend.CacheDelegate.cache(_:willEvictObject:) (<compiler-generated>)
7  CoreFoundation                 0x2336d38cc __NSCacheCallDelegateWillEvictObjectCallbackWithValue + 80
8  CoreFoundation                 0x2336d3370 __NSCacheValueRelease + 128
9  libcache.dylib                 0x232ff522c _value_entry_remove + 108
10 libcache.dylib                 0x232ff3d8c _entry_remove + 144
11 libcache.dylib                 0x232ff404c cache_remove_with_block + 256
12 CoreFoundation                 0x2336d36f8 __NSCacheApplicationDidEnterBackgroundCallBack + 128
13 CoreFoundation                 0x233606318 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 20
14 CoreFoundation                 0x2336062e4 ___CFXRegistrationPost_block_invoke + 64
15 CoreFoundation                 0x2336057d8 _CFXRegistrationPost + 392
16 CoreFoundation                 0x233605484 ___CFXNotificationPost_block_invoke + 96
17 CoreFoundation                 0x23357ed64 -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1496
18 CoreFoundation                 0x233604f34 _CFXNotificationPost + 696
19 Foundation                     0x233fed7f4 -[NSNotificationCenter postNotificationName:object:userInfo:] + 68
20 UIKitCore                      0x25fe5ef34 __47-[UIApplication _applicationDidEnterBackground]_block_invoke + 268
21 UIKitCore                      0x25f8bc7bc +[UIViewController _performWithoutDeferringTransitions:] + 112
22 UIKitCore                      0x25fe5edb8 -[UIApplication _applicationDidEnterBackground] + 100
23 UIKitCore                      0x25f71a4cc -[__UICanvasLifecycleMonitor_Compatability deactivateEventsOnly:withContext:forceExit:completion:] + 1212
24 UIKitCore                      0x25f717bec __82-[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:]_block_invoke + 824
25 UIKitCore                      0x25f717864 -[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:] + 428
26 UIKitCore                      0x25f71c3a4 __125-[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:]_block_invoke + 220
27 UIKitCore                      0x25f71d188 _performActionsWithDelayForTransitionContext + 112
28 UIKitCore                      0x25f71c25c -[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:] + 244
29 UIKitCore                      0x25f720f5c -[_UICanvas scene:didUpdateWithDiff:transitionContext:completion:] + 360
30 UIKitCore                      0x25fa51054 -[UIApplicationSceneClientAgent scene:handleEvent:withCompletion:] + 464
31 FrontBoardServices             0x2360115d8 __80-[FBSSceneImpl updater:didUpdateSettings:withDiff:transitionContext:completion:]_block_invoke_3 + 224
32 libdispatch.dylib              0x2330d57d4 _dispatch_client_callout + 16
33 libdispatch.dylib              0x23307a5d8 _dispatch_block_invoke_direct$VARIANT$mp + 224
34 FrontBoardServices             0x23604b040 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 40
35 FrontBoardServices             0x23604acdc -[FBSSerialQueue _performNext] + 408
36 FrontBoardServices             0x23604b294 -[FBSSerialQueue _performNextFromRunLoopSource] + 52
37 CoreFoundation                 0x233627018 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
38 CoreFoundation                 0x233626f98 __CFRunLoopDoSource0 + 88
39 CoreFoundation                 0x233626880 __CFRunLoopDoSources0 + 176
40 CoreFoundation                 0x2336217bc __CFRunLoopRun + 1004
41 CoreFoundation                 0x2336210b0 CFRunLoopRunSpecific + 436
42 GraphicsServices               0x23582179c GSEventRunModal + 104
43 UIKitCore                      0x25fe57978 UIApplicationMain + 212
44 Application                    0x102099fac main + 10 (AppDelegate.swift:10)
45 libdyld.dylib                  0x2330e68e0 start + 4
Another thread:

com.onevcat.Kingfisher.ImageCache.ioQueue.5910CD41-F2C8-4876-BBB7-D21E6486B2A9
0  CoreFoundation                 0x1eb1205cc _CFRelease + 108
1  libswiftCore.dylib             0x21931c544 specialized _foreignNormalize(readIndex:endIndex:guts:outputBuffer:icuInputBuffer:icuOutputBuffer:) + 1884
2  libswiftCore.dylib             0x21928401c specialized _StringGutsSlice._foreignWithNormalizedCodeUnitsImpl(outputBuffer:icuInputBuffer:icuOutputBuffer:_:) + 132
3  libswiftCore.dylib             0x21927b25c specialized _StringGutsSlice._withNFCCodeUnits(_:) + 5508
4  libswiftCore.dylib             0x21927990c _StringGutsSlice._normalizedHash(into:) + 148
5  libswiftCore.dylib             0x21931dc50 specialized String.hash(into:) + 172
6  Application                    0x104879ae0 specialized _NativeSet.resize(capacity:) (<compiler-generated>)
7  Application                    0x104879ed8 specialized _NativeSet.insertNew(_:at:isUnique:) (<compiler-generated>)
8  Application                    0x104879dd8 specialized Set._Variant.insert(_:) (<compiler-generated>)
9  Application                    0x104a3d458 specialized MemoryStorage.Backend.storeNoThrow(value:forKey:expiration:) + 122 (MemoryStorage.swift:122)
10 Application                    0x1049ffaf4 closure #3 in ImageCache.retrieveImage(forKey:options:callbackQueue:completionHandler:) + 283 (ImageCache.swift:283)
11 Application                    0x1049e29e0 specialized CallbackQueue.execute(_:) + 559 (ImageCache.swift:559)
12 Application                    0x104a00290 closure #1 in ImageCache.retrieveImageInDiskCache(forKey:options:callbackQueue:completionHandler:) (<compiler-generated>)
13 Application                    0x1049eb184 partial apply for closure #2 in CallbackQueue.execute(_:) (<compiler-generated>)
14 Application                    0x10468df58 thunk for @escaping @callee_guaranteed () -> () (<compiler-generated>)
15 libdispatch.dylib              0x1eabcca38 _dispatch_call_block_and_release + 24
16 libdispatch.dylib              0x1eabcd7d4 _dispatch_client_callout + 16
17 libdispatch.dylib              0x1eaba8dec _dispatch_lane_serial_drain$VARIANT$armv81 + 548
18 libdispatch.dylib              0x1eaba992c _dispatch_lane_invoke$VARIANT$armv81 + 408
19 libdispatch.dylib              0x1eabb1e08 _dispatch_workloop_worker_thread + 584
20 libsystem_pthread.dylib        0x1eadad114 _pthread_wqthread + 304
21 libsystem_pthread.dylib        0x1eadafcd4 start_wqthread + 4

@zdo
Copy link

zdo commented Jul 31, 2019

It seems that there are simultaneous insert and remove in Set.
Probably we need to do lock/unlock in CacheDelegate too. May be this patch could help:

--- /tmp/a      2019-07-31 16:01:00.000000000 +0300
+++ /tmp/b      2019-07-31 16:41:44.000000000 +0300
@@ -46,7 +46,7 @@
         var keys = Set<String>()
 
         var cleanTimer: Timer? = nil
-        let lock = NSLock()
+        let lock = NSRecursiveLock()
 
         let cacheDelegate = CacheDelegate<StorageObject<T>>()
 
@@ -69,6 +69,8 @@
             storage.countLimit = config.countLimit
             storage.delegate = cacheDelegate
             cacheDelegate.onObjectRemoved.delegate(on: self) { (self, obj) in
+                self.lock.lock()
+                defer { self.lock.unlock() }
                 self.keys.remove(obj.key)
             }
 

@onevcat
Copy link
Owner

onevcat commented Aug 9, 2019

@zdo Yes. You are right!

But I do not quite want to introduce a recursive lock into the project. It is a bit lazy and hides some fact of locking resource. I would check whether we can keep using normal lock for this purpose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants