Sdwebimage: Crash: SDWebImageDownloaderOperation.m line 85

Created on 8 Apr 2017  路  16Comments  路  Source: SDWebImage/SDWebImage

New Issue Checklist

Issue Info

Info | Value |
-------------------------|-------------------------------------|
Platform Name | iOS
Platform Version | iOS 8, 9, 10
SDWebImage Version | 4.0.0
Integration Method | cocoapods /
Xcode Version | Xcode 8.2.1
Repro rate | only found 6 crashes during last 30 days
Repro with our demo prj | hard to reproduce
Demo project link | no

Issue Description and Steps

Crashed: com.apple.main-thread
0  libobjc.A.dylib                0x19489bbdc objc_msgSend + 28
1  CoreFoundation                 0x182f41458 CFRelease + 524
2  CFNetwork                      0x182999f38 HTTPRequestParserClient::~HTTPRequestParserClient() + 52
3  CFNetwork                      0x182999ef4 HTTPRequestMessage::~HTTPRequestMessage() + 80
4  CoreFoundation                 0x182f41394 CFRelease + 328
5  CFNetwork                      0x18299a144 URLRequest::~URLRequest() + 152
6  CoreFoundation                 0x182f41394 CFRelease + 328
7  CFNetwork                      0x182aa9e68 -[NSURLRequestInternal dealloc] + 40
8  CFNetwork                      0x182aab124 -[NSURLRequest dealloc] + 48
9  libobjc.A.dylib                0x194886b1c object_cxxDestructFromClass(objc_object*, objc_class*) + 148
10 libobjc.A.dylib                0x194893f38 objc_destructInstance + 92
11 libobjc.A.dylib                0x194893f90 object_dispose + 28
12 Foundation                     0x183e96b14 -[NSOperation dealloc] + 104
13 ??????                         0x1008ae4fc -[SDWebImageDownloaderOperation dealloc] (SDWebImageDownloaderOperation.m:85)
14 libsystem_blocks.dylib         0x194f31910 _Block_release + 256
15 libdispatch.dylib              0x194ed9954 _dispatch_client_callout + 16
16 libdispatch.dylib              0x194ede20c _dispatch_main_queue_callback_4CF + 1608
17 CoreFoundation                 0x18301b7f8 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
18 CoreFoundation                 0x1830198a0 __CFRunLoopRun + 1492
19 CoreFoundation                 0x182f452d4 CFRunLoopRunSpecific + 396
20 GraphicsServices               0x18c75b6fc GSEventRunModal + 168
21 UIKit                          0x187b0afac UIApplicationMain + 1488
22 ??????                         0x100144178 main (main.m:14)
23 libdyld.dylib                  0x194f06a08 start + 4

@CodeStage mentioned this in #1821 . I think it's better to open a new one.

crash

Most helpful comment

I fix this by using AlamofireImage instead..
It's more effective with more possibility.

Same use as SDWebImage:
SDWebImage:
_imageView.sd_setImage(with: URL: url, placeholderImage: UIImage(named: "placeholder.png"))
AlamofireImage:
_imageView.af_setImage(withURL: url, placeholderImage: UIImage(named: "placeholder.png"))

All 16 comments

Same issue here,

- (void)cancelInternal {
    if (self.isFinished) return;
    [super cancel];

    if (self.dataTask) {
        [self.dataTask cancel];
        dispatch_async(dispatch_get_main_queue(), ^{
            [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:self];
        });

        // As we cancelled the connection, its callback won't be called and thus won't
        // maintain the isFinished and isExecuting flags.
        if (self.isExecuting) self.executing = NO;
        if (!self.isFinished) self.finished = YES;
    }

    [self reset];
}

EXC_BAD_ACCESS when dispatch_async stop notification

does this fix the issue?

We also met this crash SDWebImageDownloaderOperation.m:85, how to fix?

https://github.com/rs/SDWebImage/pull/1858 should fix it, we didn't use the weak/strong ref dance because the notification object is not being used anywhere.

it doesn't work for changing object:self to object:nil, and SDWebImageDownloaderOperation.m:85 crashes again.

@zengql512 are you getting the same stack trace?

@billyto yes, crash stack info is the same as before.

You are correct, the #1858 only fixes https://github.com/rs/SDWebImage/issues/1807 , both seems like both are related.

Is there any solution to fix this crash?

Hi,

Started seeing this issue after updating to SDWebImage 4.0 in the latest version of our app. Please have a look at the attached log. Also is there a fix coming soon?
crashreport.txt

Thanks,
Suraj

We also met this crash , v4.0,
how to fix this crash?

I fix this by using AlamofireImage instead..
It's more effective with more possibility.

Same use as SDWebImage:
SDWebImage:
_imageView.sd_setImage(with: URL: url, placeholderImage: UIImage(named: "placeholder.png"))
AlamofireImage:
_imageView.af_setImage(withURL: url, placeholderImage: UIImage(named: "placeholder.png"))

We are also seeing this crash happening in a heavily-used application. Any thoughts on a fix for it?

@rami-ihr #1858 seems a valid one. You may want to give it a try.

  • (void)cancelInternal {
    if (self.isFinished) return;
    [super cancel];

    if (self.dataTask) {
    [self.dataTask cancel];
    dispatch_async(dispatch_get_main_queue(), ^{
    [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:self];
    });

    // As we cancelled the connection, its callback won't be called and thus won't
    // maintain the isFinished and isExecuting flags.
    if (self.isExecuting) self.executing = NO;
    if (!self.isFinished) self.finished = YES;
    

    }

    [self reset];
    }
    EXC_BAD_ACCESS when dispatch_async stop notification

SAME ISSUE -> When can we get the update ???????

Should be fixed by #1940 - closing for now

Was this page helpful?
0 / 5 - 0 ratings