SDWebImage: dispatch_barrier_sync blocks main thread when re-requesting an image.

I’m using UIImageView+WebCache to load some images into a bunch of UICollectionViewCells. Instead of the nice scrolling I’m used to, the screen will occasionally entirely freeze up, the collection view scrolling animations will pause, and touches do nothing. Turns out, a semaphore_wait_trap caused by a dispatch_barrier_sync is blocking the main thread.

This only happens when an image request was cancelled, and then started again. It’s fine for cached images. Pretty sure all of this should be done on a background thread.

I’m only calling setImageURL:withPlaceholderImage: so no fancy stuff.

Edit: This will only reproduce on device. Issue is present on iPhone 4 (7.1.1) and latest gen iPod Touch (7.1.2). Not present on iPhone 5 (7.0.6).

* thread #1: tid = 0xaba2, 0x396dcaa8 libsystem_kernel.dylib`semaphore_wait_trap + 8, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
  * frame #0: 0x396dcaa8 libsystem_kernel.dylib`semaphore_wait_trap + 8
    frame #1: 0x39751bac libsystem_platform.dylib`_os_semaphore_wait + 12
    frame #2: 0x39626c3e libdispatch.dylib`_dispatch_barrier_sync_f_slow + 134
    frame #3: 0x001d1854 ama`-[SDWebImageDownloader addProgressCallback:andCompletedBlock:forURL:createCallback:](self=0x16879790, _cmd=0x00215fb0, progressBlock=0x00000000, completedBlock=0x27d9cc94, url=0x1683c050, createCallback=0x27d9c9bc) + 396 at SDWebImageDownloader.m:180
    frame #4: 0x001d05b2 ama`-[SDWebImageDownloader downloadImageWithURL:options:progress:completed:](self=0x16879790, _cmd=0x00216078, url=0x1683c050, options=0, progressBlock=0x00000000, completedBlock=0x27d9cc94) + 406 at SDWebImageDownloader.m:111
    frame #5: 0x001d759e ama`__64-[SDWebImageManager downloadWithURL:options:progress:completed:]_block_invoke59(.block_descriptor=<unavailable>, image=0x00000000, cacheType=SDImageCacheTypeDisk) + 1702 at SDWebImageManager.m:137
    frame #6: 0x001cc7fe ama`__42-[SDImageCache queryDiskCacheForKey:done:]_block_invoke_2(.block_descriptor=<unavailable>) + 42 at SDImageCache.m:297
    frame #7: 0x39614832 libdispatch.dylib`_dispatch_call_block_and_release + 10
    frame #8: 0x3961481e libdispatch.dylib`_dispatch_client_callout + 22
    frame #9: 0x39614776 libdispatch.dylib`_dispatch_main_queue_callback_4CF$VARIANT$up + 254
    frame #10: 0x2e9468a0 CoreFoundation`__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8
    frame #11: 0x2e945174 CoreFoundation`__CFRunLoopRun + 1300
    frame #12: 0x2e8afebe CoreFoundation`CFRunLoopRunSpecific + 522
    frame #13: 0x2e8afca2 CoreFoundation`CFRunLoopRunInMode + 106
    frame #14: 0x337b5662 GraphicsServices`GSEventRunModal + 138
    frame #15: 0x311fc14c UIKit`UIApplicationMain + 1136
    frame #16: 0x0009d1a4 ama`main(argc=1, argv=0x27d9dd04) + 116 at main.m:16

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 20 (8 by maintainers)

Most upvoted comments

I have the same issue here in 4.0.

The main thread hangs and when I pause the execution in Xcode, this is what I get.

capture d ecran 2017-05-22 20 48 04

(sorry for the screenshot, not sure how I can output this as text)