"Thread 6 com.apple.NSURLConnectionLoader: Program received signal: EXC_BAD_ACCESS"

22,031

Solution 1

The fix in the comment above didn't end up fixing it after all and it was still crashing at random times with almost no debug info.

With the debugger connected to my iPhone it gave a different error to the emulator and I saw a reference to a NSURLCache object. I then remembered I had some old code left over from trying to fix a memory leak in the NSURLConnection object...

NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
[NSURLCache setSharedURLCache:sharedCache];
[sharedCache release];

and also in another class I had...

    [[NSURLCache sharedURLCache] setMemoryCapacity:0];
    [[NSURLCache sharedURLCache] setDiskCapacity:0];

Removing these fixed the problem and also explained to me why it was so hard to track down. This looks to me like a bug somewhere in Apple's code as it was a total pain to track down with almost no error messages.

I hope that helps someone else.

Solution 2

Set NSZombieEnabled, MallocStackLogging, and guard malloc in the debugger. Then, when your App crashes, type this in the gdb console:

(gdb) info malloc-history 0x543216

Replace 0x543216 with the address of the object that caused the crash, and you will get a much more useful stack trace and it should help you pinpoint the exact line in your code that is causing the problem.

See this article for more detailed instructions.

Solution 3

Thanks iamichi for your efforts in tracking down this bug. This fixed my issue.

One thing to note:

I removed the following code from my app just as you did:

NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
[NSURLCache setSharedURLCache:sharedCache];
[sharedCache release];

and placed the following code (didn't remove) in the application delegate:

[[NSURLCache sharedURLCache] setMemoryCapacity:0];
[[NSURLCache sharedURLCache] setDiskCapacity:0];

All is well. Thanks!

Share:
22,031
iamichi
Author by

iamichi

Updated on March 20, 2020

Comments

  • iamichi
    iamichi over 4 years

    The app crashes about 15 seconds after launching and XCode just breaks at an address and gives me a pop up that says "Thread 6 com.apple.NSURLConnectionLoader: Program received signal: EXC_BAD_ACCESS"

    I've been totally unable to track the problem down. It works fine running on iOS 4, but I'm guessing that's just because it is more tolerant of the bug or something. I've tried setting breakpoints everywhere and stepping through, running it in Instruments under the Zombies profile, but it just bombs out and doesn't tell me where. I've got not warnings and a clean analysis, so I'm at a bit of a loss where to look next. Can anyone offer any advise? Thanks.

    The backtrace is:

    (gdb) backtrace
    #0  0x024fb939 in _dispatch_retain ()
    #1  0x024fbc02 in dispatch_source_cancel ()
    #2  0x0109e492 in _CFURLCacheDeallocate ()
    #3  0x0205a4e3 in CFRelease ()
    #4  0x010331b1 in HTTPProtocol::~HTTPProtocol ()
    #5  0x0100c75d in CFClass::FinalizeObj ()
    #6  0x0205a4e3 in CFRelease ()
    #7  0x02110af0 in __CFDictionaryStandardReleaseValue ()
    #8  0x020714b1 in __CFBasicHashDrain ()
    #9  0x0205a4e3 in CFRelease ()
    #10 0x01024237 in SocketStream::~SocketStream ()
    #11 0x0100c75d in CFClass::FinalizeObj ()
    #12 0x0205a4e3 in CFRelease ()
    #13 0x01023e0b in SocketStream::finalize ()
    #14 0x01023dc6 in virtual thunk to SocketStream::finalize(void const*) ()
    #15 0x01023da1 in ReadStreamCallbacks::_finalize ()
    #16 0x0208201a in __CFStreamDeallocate ()
    #17 0x0205a4e3 in CFRelease ()
    #18 0x01030a6c in HTTPReadFilter::~HTTPReadFilter ()
    #19 0x0100c75d in CFClass::FinalizeObj ()
    #20 0x0205a4e3 in CFRelease ()
    #21 0x010c22bc in non-virtual thunk to HTTPReadFilter::readStreamFinalize(__CFReadStream*) ()
    #22 0x0102ff1c in CFNetworkReadStream::httpStreamFinalize ()
    #23 0x0208201a in __CFStreamDeallocate ()
    #24 0x0205a4e3 in CFRelease ()
    #25 0x0103070f in NetConnection::shutdownConnectionStreams ()
    #26 0x010bf1fc in NetConnection::closeStreamsIfPossibleOrSignalThatThatNeedsToBeDonePrettyPlease ()
    #27 0x0103485b in HTTPConnectionCacheEntry::removeUnauthConnection ()
    #28 0x010d6d2d in HTTPConnectionCacheEntry::purgeIdleConnections ()
    #29 0x010d3c1e in ConnectionCacheTLS::resetCacheForThisThread ()
    #30 0x0101b739 in ConnectionTimerTLS::_timerPurgeEntries ()
    #31 0x02122966 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ ()
    #32 0x02122407 in __CFRunLoopDoTimer ()
    #33 0x020857c0 in __CFRunLoopRun ()
    #34 0x02084db4 in CFRunLoopRunSpecific ()
    #35 0x02084ccb in CFRunLoopRunInMode ()
    #36 0x00206e40 in +[NSURLConnection(Loader) _resourceLoadLoop:] ()
    #37 0x001184e6 in -[NSThread main] ()
    #38 0x00118457 in __NSThread__main__ ()
    #39 0x98d6b259 in _pthread_start ()
    #40 0x98d6b0de in thread_start ()
    
  • iamichi
    iamichi over 12 years
    Thanks for the help. I followed this guide, but when I enter info malloc-history and the address where it fell over, I get nothing. See this screengrab. Can you think of why that might be?
  • chown
    chown over 12 years
    Thats the wrong hex address. You want to use the address of the actual object that is causing the crash. See if any of the threads show actual code instead of registers, then hover the mouse over an object in that code to get its hex address.
  • iamichi
    iamichi over 12 years
    The only thread that gives me any code is Thread 1, with the main function. I've tried every address it gives me in the thread that crashes. Nothing is being logged out to the console, just [Switching to process 53537 thread 0x5307] before it crashes. I've tried commenting out all the NSURLConnections in the project as well and still no dice. I appreciate your help, is there anything else you can suggest?
  • chown
    chown over 12 years
    Hmm, you could set a breakpoint in your applicationDidFinishLaunching method, then step throuh it line by line to find which line executes just before the crash.
  • iamichi
    iamichi over 12 years
    Yeah, I tried that, but it happens in another thread about 5 seconds after the app has finished launching and I finish stepping through all that code. I can't find for the life of me what is launching it or what it is doing. I think I'll try reverting to previous versions of the project in mercurial and see if any older versions work on iOS 5. Thanks again for the input. :)
  • iamichi
    iamichi over 12 years
    No joy going back as far as I can, same problem, so it must have existed for a long time. I guess I'll submit a technical support request to Apple then.
  • iamichi
    iamichi over 12 years
    I managed to resolve it by commenting out large parts of the code at a time and running it until it didn't crash, then I narrowed it down and found the part that was causing the problem. I'm still not quite sure exactly what caused it as I couldn't spare more time working it out, but I have refactored the relevant code and it seems to be fine now, no crashes and no warnings. :)
  • iamichi
    iamichi over 12 years
    Thanks, that's useful to know as well. Glad that helped you, as it was a bit of a head scratcher.
  • dwlz
    dwlz over 8 years
    The first two links here 404.
  • SomethingOn
    SomethingOn over 7 years
    Where in the AppDelegate.m file did you put this?