views:

136

answers:

2

Hi guys.

I sometimes get crash reports about an EXC_BAD_ACCESS with NSURLConnection (i guess it's about NSURLConnection according to crash reports).

I found a question here on StackOverflow with the same kind of report but nothing helped there :/ (http://stackoverflow.com/questions/3111051/nsurlconnection-causes-bad-access-crash); i tried running the app with NSZombieEnabled but since this issue is really "random" i never managed to get it while running with NSZombieEnabled :/

Anyone having a hint ?

Thanks a lot :)

Here's a repport :

Thread 3 Crashed:
0   libobjc.A.dylib                0x0000286c objc_msgSend + 16
1   CoreFoundation                 0x0000325c CFEqual + 92
2   CoreFoundation                 0x000b081c __CFBasicHashStandardEquateKeys + 12
3   CoreFoundation                 0x000b2578 ___CFBasicHashFindBucket_Linear + 216
4   CoreFoundation                 0x00002ff8 CFBasicHashFindBucket + 220
5   CoreFoundation                 0x00002ec6 CFDictionaryGetValue + 50
6   CFNetwork                      0x0005853a HTTPMessage::copyConstantHeaderFieldValue(unsigned int) const + 26
7   CFNetwork                      0x00090024 URLRequest::copyConstantHeaderFieldValue(unsigned int) const + 20
8   CFNetwork                      0x0008ce0e HTTPProtocol::getCacheStoragePolicy(__CFHTTPMessage*) + 158
9   CFNetwork                      0x0008e6c8 HTTPProtocol::updateForHeader(__CFHTTPMessage*) + 492
10  CFNetwork                      0x0008f73c HTTPProtocol::performHeaderRead() + 368
11  CFNetwork                      0x0008fbea HTTPProtocol::httpReadStreamEvent(unsigned long) + 110
12  CFNetwork                      0x0008fd34 HTTPProtocol::_httpReadStreamCB(__CFReadStream*, unsigned long, void*) + 4
13  CoreFoundation                 0x0004985e _signalEventSync + 70
14  CoreFoundation                 0x000497f2 _cfstream_shared_signalEventSync + 198
15  CoreFoundation                 0x00071a86 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 6
16  CoreFoundation                 0x000736ac __CFRunLoopDoSources0 + 188
17  CoreFoundation                 0x00074504 __CFRunLoopRun + 224
18  CoreFoundation                 0x0001d8e4 CFRunLoopRunSpecific + 224
19  CoreFoundation                 0x0001d7ec CFRunLoopRunInMode + 52
20  Foundation                     0x0003b71e +[NSURLConnection(NSURLConnectionReallyInternal) _resourceLoadLoop:] + 206
21  Foundation                     0x0000bc96 -[NSThread main] + 38
22  Foundation                     0x000909da __NSThread__main__ + 966
23  libSystem.B.dylib              0x0007a986 _pthread_start + 242
24  libSystem.B.dylib              0x000700e4 thread_start + 0

Update

I finally managed to get the error while NSZombieEnabled is on ... but it doesn't help much :/

Here's the backtrace :

[Switching to thread 13059]
Program received signal:  “EXC_BAD_ACCESS”.
[Switching to thread 13059]
(gdb) bt
#0  0x3090ce9c in CFDictionaryGetValue ()
#1  0x35233540 in HTTPMessage::copyConstantHeaderFieldValue ()
#2  0x3526b02a in URLRequest::copyConstantHeaderFieldValue ()
#3  0x35267e14 in HTTPProtocol::getCacheStoragePolicy ()
#4  0x352693e2 in HTTPProtocol::attemptToCacheMovedPermanently ()
#5  0x3526a6c8 in HTTPProtocol::performHeaderRead ()
#6  0x3526abf0 in HTTPProtocol::httpReadStreamEvent ()
#7  0x3526ad3a in HTTPProtocol::_httpReadStreamCB ()
#8  0x30953864 in _signalEventSync ()
#9  0x309537f8 in _cfstream_shared_signalEventSync ()
#10 0x3097ba8c in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ ()
#11 0x3097d6b2 in __CFRunLoopDoSources0 ()
#12 0x3097e50a in __CFRunLoopRun ()
#13 0x309278ea in CFRunLoopRunSpecific ()
#14 0x309277f2 in CFRunLoopRunInMode ()
#15 0x3148b724 in +[NSURLConnection(NSURLConnectionReallyInternal) _resourceLoadLoop:] ()
#16 0x3145bc9c in -[NSThread main] ()
#17 0x314e09e0 in __NSThread__main__ ()
#18 0x3129298c in _pthread_start ()
#19 0x312880ec in thread_start ()
(gdb) 
+2  A: 

I'm not sure there's really enough information to provide much help :-(

Firstly, do persist with NSZombie's - I'm sure in time you will get it to happen. Do make sure you check the console output, there's a small chance the exception that nszombie throws could be getting caught and ignored somewhere.

Other than that, just double check everything you do with memory. Make sure the request is cancelled before being released, that you never accidentally overwrite a pointer to a running request with another request, make sure you're not overreleasing any objects you're passing to the request.

One final suggestion that may or may not solve your problem would be to try ASIHTTPRequest instead:

http://allseeing-i.com/ASIHTTPRequest/

It can do everything NSURLConnection can do (and a lot of useful things in addition), and if you still get crashes you'll at least have the source so you can get more information about what is going wrong.

JosephH
+1 for asihttprequest as it is just so problem free
hib
Ah yes pretty good advice :) Gonna check it right away
Vivi
Just had the error with NSZombieEnabled ... but the backtrace doesn't help much :
Vivi
Can you edit the backtrace and any console output into the question?
JosephH
I edited the question with my console "bt" output
Vivi
You're right, that's not much help :-(
JosephH
I'm trying to use the XCode Debugger (with Breakpoints) to show me what thread is using the crashy NSURLConnection but i can't get it to backtrace its parent; any idea? :)
Vivi
That backtrace you supplied is from NSURLConnection's thread (ie. the thread that gets started to run the request on) - I'm not sure you can get back to the original thread. Note that NSURLConnection callbacks will arrive on the thread you started the request from, so be careful not to kill off that thread, etc.
JosephH
You may be able to identify which request it is though. Firstly, add an NSLog(@"starting NSURLConnection %p", request) each place you start the request, then if you navigate up your backtrace you might be able to find that same pointer value in "self" or similar.
JosephH
A: 

Ok I found the solution / problem.

My code was OK, the origin of the problem is that I was trying to get images from my website using these NSURLConnections ... but our SEO guys changed the images urls so i had redirected requests.

NSURLConnection doesn't like redirected requests much.

Thanks for help!

Vivi