NSURLConnection sendSynchronousRequest and NSString stringWithContentsOfURL crashing under 10.5.7
NSURLConnection sendSynchronousRequest and NSString stringWithContentsOfURL crashing under 10.5.7
- Subject: NSURLConnection sendSynchronousRequest and NSString stringWithContentsOfURL crashing under 10.5.7
- From: Dennis Hartigan-O'Connor <email@hidden>
- Date: Wed, 27 May 2009 10:49:39 -0700
I have a little app that downloads stock prices and was working
perfectly (for years) until my recent upgrade to 10.5.7. After the
upgrade, the program would crash on this call:
NSString *currinfo = [NSString stringWithContentsOfURL:[NSURL
URLWithString:[NSString
stringWithFormat:@"http://finance.yahoo.com/d/quotes.csv?s=%@&f=l1c1p2",
escsymbol]]];
Oddly, the crash doesn't happen right away. This line of code is called
many times, with no problems, and then the program eventually fails
after 1-2 hours due to a crash on this call.
Seeing that stringWithContentsOfURL is deprecated, I switched to this code:
pathURL = [NSURL URLWithString:[NSString
stringWithFormat:@"http://finance.yahoo.com/d/quotes.csv?s=%@&f=l1c1p2",
escsymbol]];
NSURLRequest *request = [NSURLRequest requestWithURL:pathURL
cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:30.0];
responseData = [ NSURLConnection sendSynchronousRequest:request
returningResponse:&response error:&error];
NSString *currinfo = nil;
if ([error code]) { dNSLog((@"%@ %d %@ %@ %@", [ error domain], [ error
code], [ error localizedDescription], request,
@"file://localhost/etc/gettytab")); }
This didn't help. The program still crashes on the
sendSynchronousRequest line after an arbitrary length of time, with this
information in the debugger:
0 0x93db7286 in mach_msg_trap
1 0x93dbea7c in mach_msg
2 0x946ba04e in CFRunLoopRunSpecific
3 0x946bac78 in CFRunLoopRunInMode
4 0x932b53eb in CFURLConnectionSendSynchronousRequest
5 0x905dca4b in +[NSURLConnection
sendSynchronousRequest:returningResponse:error:]
...etc.
The real crash might actually be in a different thread:
0 libobjc.A.dylib 0x965c3688 objc_msgSend + 24
1 com.apple.CoreFoundation 0x946cc581 _CFStreamSignalEventSynch
+ 193
2 com.apple.CoreFoundation 0x946ba595 CFRunLoopRunSpecific + 3141
3 com.apple.CoreFoundation 0x946bac78 CFRunLoopRunInMode + 88
4 com.apple.Foundation 0x9058c530
+[NSURLConnection(NSURLConnectionReallyInternal) _resourceLoadLoop:] + 320
5 com.apple.Foundation 0x90528e0d -[NSThread main] + 45
6 com.apple.Foundation 0x905289b4 __NSThread__main__ + 308
7 libSystem.B.dylib 0x93de8155 _pthread_start + 321
8 libSystem.B.dylib 0x93de8012 thread_start + 34
which I presume is the thread spawned to download the URL. By the way,
the error handling code works fine--when I intentionally cause an error
by disconnecting from the internet, the error is just reported in the
console and the program doesn't crash.
This is incredibly frustrating. I would be very happy to spend as much
time as necessary tracking down the problem, but I'm kind of at the
limits of my knowledge with gdb and especially with assembly language. I
don't know how to find out what is the actual problem for the Foundation
code. At first I thought that maybe the autoreleased NSString escsymbol
is somehow being deallocated, but sending it a retain message didn't
help. If this were the case, how could I prove it?
Is anybody else having this problem?
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden