SDWebImageSwiftUI icon indicating copy to clipboard operation
SDWebImageSwiftUI copied to clipboard

App freezes when imageURL fails caused by infinite loop

Open alanscarpa opened this issue 2 years ago • 4 comments

Xcode 13 iOS 14+

When my model retrieves its image URL, the following code is called:

if let imageURL = model.profilePhotoURL, !imageURL.absoluteString.isEmpty {
                            AnimatedImage(url: imageURL).onFailure(perform: { error in
                                print("we got an error")
                            })

Turns out my imageURL was a little misinformed, so loading the image fails.

The issue is that the app freezes on failure. And when I print "we got an error" I can see that we are stuck in an infinite loop, as it gets called over and over. This is causing the app to freeze.

Is there a resolution?

alanscarpa avatar Oct 15 '21 19:10 alanscarpa

Please attach the stack trace when your App freeze. Or any demo ?

dreampiggy avatar Oct 18 '21 03:10 dreampiggy

We also see this behaviour. This is a very scary bug.

CWftw avatar Mar 23 '22 19:03 CWftw

I'm experiencing this too. The app freezes and its memory usages grows forever:

memory

This issue seems to happen when loading unreachable URLs in your library. For example, this SwiftUI code causes the issue:

@ViewBuilder var profileImage: some View {
	AnimatedImage(url: URL(string: "https://avatars.blue.ravetel.com/test.jpeg")!)
		.resizable()
		.aspectRatio(contentMode: .fill)
		.frame(maxWidth: 200, maxHeight: 200, alignment: .center)
		.clipShape(Circle())
}

SDWebImage is a really great help for my app. My team and I really appreciate your work.

That said, this is a very serious issue: apps should not freeze when their network requests fail.

An urgent fix would be very much appreciated.

jordaneckhardt avatar Mar 23 '22 22:03 jordaneckhardt

Hi. This SDWebImageSwiftUI seems lag of long-time maintainess. Any contributor can help with ?

To fix this, I guess we should replace all the usage of @State which binding a class, to use the @StateObject. (example: ImageManager is class, so should change it into @StateObject)

Which bump the min deployment target to iOS 14+


I recently not focus on mobile iOS UI-related development and works on Swift compiler stack related stuff. So maybe I can not manitain too many SDWebImage related project as previous. :(

dreampiggy avatar Mar 24 '22 10:03 dreampiggy

I retested in SDWebImageSwiftUI version 2.2.1 and the issue appears to be fixed.

jordaneckhardt avatar Oct 26 '22 17:10 jordaneckhardt