SDWebImage / SDWebImageSwiftUI

SwiftUI Image loading and Animation framework powered by SDWebImage
https://sdwebimage.github.io/SDWebImageSwiftUI
MIT License
2.18k stars 225 forks source link

Steadily reproducible data race #260

Closed Cyclic closed 1 year ago

Cyclic commented 1 year ago

image

Not sure where to begin here, as I've been unable to locate the conditions that are causing this issue. Things appeared to be working fine for some time, and now this.

https://user-images.githubusercontent.com/553800/230520241-36d34c29-3d2d-47e5-a218-4f32ed2742bb.mov

I noticed that the issue started occurring at the same time that while dragging the scroll view with the images would show the progressview.

            GeometryReader { geometry in
                PagingView(index: self.$focusedImageIndex, showImageList: self.$childNavigationState.showSheet, maxIndex: listing.photoContainers.count - 1) {
                    ForEach(listing.photoContainers.sorted(by: { $0.priority < $1.priority }).indices, id:\.self) { index in
                        WebImage(url: listing.photoContainers[index].url)
                            .placeholder {
                                if let _ = listing.media?.first?.url {
                                    ProgressView()
                                        .frame(maxWidth: .infinity, maxHeight: .infinity)
                                }
                            }
                            .resizable()
                            .transition(.fade(duration: 1.0))
                            .clipped()
                            .id(index)
                            .aspectRatio(contentMode: .fill)
                            .buttonStyle(PlainButtonStyle())
                    }
                }
                .onAppear {
                    if navigationState.selectedImageIndex > 0 {
                        self.focusedImageIndex = navigationState.selectedImageIndex
                    }
                }
                .environmentObject(childNavigationState)
                .frame(width: UIScreen.main.bounds.width, height: montageHeight(geometry: geometry))
                .offset(y: montageOffset(geometry: geometry))
                .contentShape(CarouselTapShape())
            }
        I tried to replace the WebImage with AsyncImage, and now I observe some similar funkiness.

        ```MetadataView: @self, @identity, _listing changed.

2023-04-06 18:12:35.239387-0700 Classify iOS[60896:5764215] [Listing+CoreDataClass] photoContainers MetadataView: @self, @identity, _listing changed. 2023-04-06 18:12:37.584048-0700 Classify iOS[60896:5764215] [Listing+CoreDataClass] photoContainers 2023-04-06 18:12:39.856369-0700 Classify iOS[60896:5764215] [Classify iOS] createDataWithMappedFile:1555: 'open' failed '/Users/goddard/Library/Developer/CoreSimulator/Devices/1B11E68C-BCF6-4B45-8141-B7507CA83A35/data/Containers/Data/Application/903A5DE7-A762-412E-BAC1-6ABB8711A29D/tmp/CFNetworkDownload_ALWnvr.tmp' error = 2 (No such file or directory) 2023-04-06 18:12:39.856786-0700 Classify iOS[60896:5764215] [Classify iOS] createDataWithMappedFile:1555: 'open' failed '/Users/goddard/Library/Developer/CoreSimulator/Devices/1B11E68C-BCF6-4B45-8141-B7507CA83A35/data/Containers/Data/Application/903A5DE7-A762-412E-BAC1-6ABB8711A29D/tmp/CFNetworkDownload_ALWnvr.tmp' error = 2 (No such file or directory) 2023-04-06 18:12:39.856881-0700 Classify iOS[60896:5764215] [Classify iOS] copyIOSurface:88: retainBytePointer failed 2023-04-06 18:12:39.857237-0700 Classify iOS[60896:5764215] [Classify iOS] createDataWithMappedFile:1555: 'open' failed '/Users/goddard/Library/Developer/CoreSimulator/Devices/1B11E68C-BCF6-4B45-8141-B7507CA83A35/data/Containers/Data/Application/903A5DE7-A762-412E-BAC1-6ABB8711A29D/tmp/CFNetworkDownload_ALWnvr.tmp' error = 2 (No such file or directory) 2023-04-06 18:12:39.857581-0700 Classify iOS[60896:5764215] [Classify iOS] createDataWithMappedFile:1555: 'open' failed '/Users/goddard/Library/Developer/CoreSimulator/Devices/1B11E68C-BCF6-4B45-8141-B7507CA83A35/data/Containers/Data/Application/903A5DE7-A762-412E-BAC1-6ABB8711A29D/tmp/CFNetworkDownload_ALWnvr.tmp' error = 2 (No such file or directory) 2023-04-06 18:12:39.859195-0700 Classify iOS[60896:5764215] [Classify iOS] createDataWithMappedFile:1555: 'open' failed '/Users/goddard/Library/Developer/CoreSimulator/Devices/1B11E68C-BCF6-4B45-8141-B7507CA83A35/data/Containers/Data/Application/903A5DE7-A762-412E-BAC1-6ABB8711A29D/tmp/CFNetworkDownload_ALWnvr.tmp' error = 2 (No such file or directory) 2023-04-06 18:12:39.859285-0700 Classify iOS[60896:5764215] [Classify iOS] copyIOSurface:88: retainBytePointer failed 2023-04-06 18:12:39.859785-0700 Classify iOS[60896:5764215] [Classify iOS] createDataWithMappedFile:1555: 'open' failed '/Users/goddard/Library/Developer/CoreSimulator/Devices/1B11E68C-BCF6-4B45-8141-B7507CA83A35/data/Containers/Data/Application/903A5DE7-A762-412E-BAC1-6ABB8711A29D/tmp/CFNetworkDownload_ALWnvr.tmp' error = 2 (No such file or directory) 2023-04-06 18:12:39.865420-0700 Classify iOS[60896:5764215] Warning! [0x16341f800] Decoding incomplete with error code -1. This is expected if the image has not been fully downloaded. 2023-04-06 18:12:39.870081-0700 Classify iOS[60896:5764215] [0x16341f800] Decoding: C0 0x0BB807D2 0x00BC304A 0x22111100 0x001F8006 4395292 2023-04-06 18:12:39.870151-0700 Classify iOS[60896:5764215] [0x16341f800] Options: 3000x2002 [FFFFFFFF,FFFFFFFF] 00025060



I'm also seeing this in the console logs when using AsyncImage
```onChange(of: Optional<URL>) action tried to update multiple times per frame.
onChange(of: Optional<URL>) action tried to update multiple times per frame.```

Any idea what might be causing this unusual behavior?
![Simulator Screen Recording - iPhone 14 Pro Max - 2023-04-06 at 18 14 57](https://user-images.githubusercontent.com/553800/230520794-ec5e7548-0c0e-47ec-b76f-5fce790156ac.gif)
![Simulator Screen Recording - iPhone 14 Pro Max - 2023-04-06 at 18 14 57](https://user-images.githubusercontent.com/553800/230520937-7c9252b4-e62f-489f-9403-384576caf211.gif)
Cyclic commented 1 year ago

Closing as I discovered that I added a random timestamp to the URL to invalidate the cache, and it was running on every frame, causing some serious issues.