Sdwebimage: iOS10 Crash issue

Created on 15 Jul 2016  ·  17Comments  ·  Source: SDWebImage/SDWebImage

http://c2n.me/3AeWEaQ

Application Specific Information:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* setObjectForKey: object cannot be nil (key: file:///private/var/mobile/Containers/Data/Application/7B44B366-DB39-4EBE-B8F8-AE7B8989862F/Library/Caches/default/com.hackemist.SDWebImageCache.default/00818936d4c06d1b8246c0fc6fdb39ef.jpg)'

Last Exception Backtrace:
0 CoreFoundation 0x0000000187643eb0 0x187519000 + 1224368
1 libobjc.A.dylib 0x0000000186c3c4a8 0x186c34000 + 33960
2 CoreFoundation 0x0000000187528ec4 0x187519000 + 65220
3 Новости 0x0000000100ccc698 __45-[SDImageCache cleanDiskWithCompletionBlock:]_block_invoke (SDImageCache.m:548)

crash

Most helpful comment

0edecd11-bc51-4750-bd62-66727e6714da
Something wrong occurred in place "1", this could cause resourceValues with nil value, thus, cause place "2" set a nil value into cacheFiles dictionary

All 17 comments

0edecd11-bc51-4750-bd62-66727e6714da
Something wrong occurred in place "1", this could cause resourceValues with nil value, thus, cause place "2" set a nil value into cacheFiles dictionary

@rs @JasF @jparise

我也遇到了这个问题,如何解?求教。

I'm seeing a rise in these exceptions due to public beta and an imminent release of iOS10.

Usually happens when an user sends the app to the background.
I don't have a demo project with 100% chance to reproduce, but setting the cache timeout to 1 second and sending the app into the background(after some images have been cached) seems to make the app crash quite frequently(to then be able to reproduce and fix of course).

@jimmaye You've found out the scene where the crash happened. Anyway, rule out the reason of system's version, I think author shoud do something to prevent it and keep the code stronger.

@jjj2mdd It seems not working. I changed my code as you noted, link, but it still crashes on line NSDictionary *resourceValues = [fileURL resourceValuesForKeys:resourceKeys error:&error]; itself. It seems a bug of Apple not SDWebImage.

Crashed: com.hackemist.SDWebImageCache
0 libsystem_kernel.dylib 0x1888fe014 __pthread_kill + 8
1 libsystem_pthread.dylib 0x1889c5460 pthread_kill + 112
2 libsystem_c.dylib 0x1888723f4 abort + 140
3 libsystem_malloc.dylib 0x188942a38 _nano_vet_and_size_of_live + 330
4 libsystem_malloc.dylib 0x188943db8 nano_free + 220
5 CoreFoundation 0x1898dfe8c _CFRelease + 1264
6 CoreServicesInternal 0x19f7e2ba0 SetNameAndExtensionLengthFromCString(__CFAllocator const_, char const_, long, _FileAttributes_) + 48
7 CoreServicesInternal 0x19f7e1ee0 parseAttributeBuffer(__CFAllocator const_, unsigned char const_, unsigned char, attrlist const_, void const_, void__, _FileAttributes_, unsigned int_) + 320
8 CoreServicesInternal 0x19f7e0148 corePropertyProviderPrepareValues(__CFURL const_, __FileCache_, __CFString const_ const_, void const__, long, void const_, __CFError) + 804
9 CoreServicesInternal 0x19f7d9ac8 prepareValuesForBitmap(__CFURL const_, __FileCache_, _FilePropertyBitmap, __CFError
) + 256
10 CoreServicesInternal 0x19f7d80e8 _FSURLCopyResourcePropertiesForKeysInternal(__CFURL const_, __CFArray const_, void_, __CFError_
, unsigned char) + 832
11 CoreFoundation 0x189905948 CFURLCopyResourcePropertiesForKeys + 300
12 CoreFoundation 0x189967684 -[NSURL resourceValuesForKeys:error:] + 192
13 HiPDA 0x10021e0f0 __45-[SDImageCache cleanDiskWithCompletionBlock:]_block_invoke (SDImageCache.m:497)
14 libdispatch.dylib 0x1887b9200 _dispatch_call_block_and_release + 24
15 libdispatch.dylib 0x1887b91c0 _dispatch_client_callout + 16
16 libdispatch.dylib 0x1887c7444 _dispatch_queue_serial_drain + 928
17 libdispatch.dylib 0x1887bc9a8 _dispatch_queue_invoke + 652
18 libdispatch.dylib 0x1887c7940 _dispatch_queue_override_invoke + 360
19 libdispatch.dylib 0x1887c938c _dispatch_root_queue_drain + 572
20 libdispatch.dylib 0x1887c90ec _dispatch_worker_thread3 + 124
21 libsystem_pthread.dylib 0x1889c12c8 _pthread_wqthread + 1288
22 libsystem_pthread.dylib 0x1889c0db4 start_wqthread + 4

@wujichao

I'll submit a PR later today with my correction of the bug. After this fix, I no longer see any crashes. For your convenience, I've pasted a screenshot of the diff below:
screen shot 2016-09-22 at 09 31 49

@jimmaye I do the same thing as you, in my fork, but it still crash. It seems a bug of Apple not SDWebImage.
You can see it crash on 13 HiPDA 0x10021e0f0 __45-[SDImageCache cleanDiskWithCompletionBlock:]_block_invoke (SDImageCache.m:497) itself.

@wujichao Seems like we're having different issues then. I've submitted a PR which fixes the problem I'm seeing, and added a unit test that actually touches the code which cleans up images. I was unable to reproduce the error in the unit test.

@jimmaye , - resourceValuesForKeys:error: seems too weird, your PR might not fix the issue
screenshot

@jjj2mdd
I've shipped a new release of the app I'm working at weeks ago, and according to crash reports, the crash is not happening anymore, hence I believe it fixes it (at least the crash we've experienced).

@jimmaye I think you do fix it.
It is a crash that hard to reproduce. My app, 6k daily activity users, only crash 16 times for about one month. 7 crashes because of SDImageCache.m line 497(link), 9 crashes because of SDImageCache.m line 551 (link) which you already fixed. All iOS10.
I do believe it is a bug of Apple not SDWebImage.

@jimmaye , sorry bro.
Yet there is a risk, that value will return nil as well as error.

@wujichao I saw around 200 crashes/day when it peaked - now I have 0. I guess there could be a bug which Apple hopefully will fix at some point

@jjj2mdd Np bro, I guess one still has to guard against nil

1676 and 7940577 should have fixed this.

@jimmaye - i'm seeing this same exact crash in an app of mine, but i am not sure how to reproduce it to find out if this commit fixes our problem. are you able to explain what steps you took to reproduce this crash?

@jeffctown
My comment from 9th september in this issue explains the steps I took to be able to reproduce the issue. Could be something like [[SDImageCache sharedImageCache] setMaxCacheAge:1]; to set a very short max cache age(remember to revert this change). I hope it can help you reproduce the crash somehow.

Was this page helpful?
0 / 5 - 0 ratings