Closed mtitolo closed 6 years ago
Hi @mtitolo. I've tried to reproduce this scenario, but without success. How is the cancelling occur? (is it the sd_cancelCurrentImageLoad
from the sd_setImageWithURL:placeholderImage:options:progress:completed:
or you are cancelling explicitly? Could you set up a demo project where the issue can be easily reproducible?
Took a bit of poking, and some symbolic breakpoint trickery, but I managed to reproduce the issue.
Code: https://github.com/mtitolo/cats/tree/sdwebimage-scrolling Here's an Instagram key to use: 42988e0cdc54410b80aceeb4309faf19
How to reproduce:
applicationDidFinishLaunching...
lldb
run breakpoint set -n semaphore_wait_trap
script
and paste in this script:find_in_stack = ['-[SDWebImageDownloader addProgressCallback:andCompletedBlock:forURL:createCallback:]']
def continue_ignored(frame, bp_loc, dict):
global find_in_stack
names = set([frame.GetFunctionName() for frame in frame.GetThread()])
all_ignored = set(find_in_stack)
ignored_here = all_ignored.intersection(names)
if len(ignored_here) == 0:
frame.GetThread().GetProcess().Continue()
quit()
_There are a number of semaphore_wait_traps
that we want to skip. We are only interested in ones with -addProgressCallback:...
in its stack frame_
br comm add -F continue_ignored 2
where 2 is the ID of the breakpoint printed from step 1 (it may be a different number).I noticed that this will also get hit in the simulator occasionally, so this looks to be the cause of jankiness in general.
HTH.
I face similar issue as well.
I'm experiencing this issue as well under crappy network conditions.
I am also facing the same issue. Loading many image in table view with sdwebimage freezes the app. You can check the threading from this link. http://io.putul.me/oQ67RC
I face similar issue as well.What's the release time for resolve this issues(version 4.0.0)? It often happen on iPhone 4 or equiv device.
Hi,
Sorry but I don’t understand the issue you’re experiencing. Could you go through what you need help with?
Best Regards, Team Sober Grid contact@sobergrid.commailto:contact@sobergrid.com
[cid:2B498DF3-5AF6-43D6-94B5-E240B78B11C8]
Share us on Facebookhttps://www.facebook.com/sharer/sharer.php?u=http://goo.gl/NglQWa Share us on Twitterhttps://twitter.com/home?status=http://goo.gl/NglQWa
On Aug 13, 2015, at 11:39 PM, yanzhiwei147 notifications@github.com<mailto:notifications@github.com> wrote:
I face similar issue as well.What's the release time for resolve this issues(version 4.0.0)? It often happen on iPhone 4 or equiv device.
— Reply to this email directly or view it on GitHubhttps://github.com/rs/SDWebImage/issues/803#issuecomment-130951702.
ref http://www.objc.io/issues/2-concurrency/concurrency-apis-and-pitfalls/#starvation barrierQueue block main thread
Same problem here. Having application freezing are a very bad user experience, as many users don't know how to kill / restart application. Any "good practice" to have ?
Edit: putting [SDWebImageDownloader.sharedDownloader setMaxConcurrentDownloads: 1];
fix the problem for me. It's better than nothing ! ;)
This issue should be fixed now, on the 4.x branch. 4.0. release is coming
this issue still there in 4.0.
using https://github.com/onevcat/Kingfisher for time being
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.
(sorry for the screenshot, not sure how I can output this as text)
@rs I think this issue should be reopened, what do you think?
Firstly, could you please try the lastest version and see if this still represent ?
@dirtyhenry This code seems changed to add a queue dispatch to ensure thread-safe, see : https://github.com/rs/SDWebImage/blob/4.2.3/SDWebImage/SDWebImageDownloader.m#L245-L252
And I want to point it out that GCD is a thread-pool. If the GCD thread pool hit the max thread count(currently is 66 on iOS, 64 + main thread + diapatch thread), then a new queue enter will cause a dead lock. So maybe this is unavoidable if your application contains so much threads. (Note not each queue use a thread, when you call dispatch_get_global_queue
, you may share a thread with another queue. Only some specify usage such dispatch_queue_create
and keep a thread-local variable may actually use a standalone thread).
@mayqiyue Maybe we should drop that usage of using dispatch_queue
, for mutable array, a dispatch_semaphore
or other lock is enough and will not cause some queue problem.
@dreampiggy Were it caused by logical problem, using other locks would lead to the same deadlock issue. However I failed to find one. Any suggestions?
@dreampiggy Sorry, I made a mistake. Our issue was not caused by SD.
@skyline75489 Actually, why we must use a dispatch_barrier_sync
? This process just need to remove the URL from a NSMutableArary, isn't ? Use GCD as a lock is a wrong design and I don't know why current code always do like this. (Because the issue I mentioned, GCD is a thead-pool and may reach the limit and cause dead-lock, it's not a silver bullet)
I suggest to use a lock (I use dispatch_semaphore
because it not so CPU-consuming like spinLock and have a balance of performance) instead. I create one PR #2184 for this.
I guess the issue is that sometimes the completionBlock on NSOperation
return the barrier queue used in downloader, so this cause a deadlock.
The exact execution context for your completion block is not guaranteed but is typically a secondary thread.
I'm using
UIImageView+WebCache
to load some images into a bunch ofUICollectionViewCell
s. 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, asemaphore_wait_trap
caused by adispatch_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).