NSXMLParser, streams, multiple threads, and crashing
NSXMLParser, streams, multiple threads, and crashing
- Subject: NSXMLParser, streams, multiple threads, and crashing
- From: Thomas Davie <email@hidden>
- Date: Sun, 22 Jan 2012 13:15:26 +0000
Hi all,
I'm having a bit of a bizarre issue with a pair of NSXMLParsers reading out of streams, where my main thread crashes while signalling a stream.
Every crash occurs in the main thread, with this back trace:
> #0 0x0175d0b0 in objc_msgSend ()
> #1 0x0133fb4d in _outputStreamCallbackFunc ()
> #2 0x0130f06d in _signalEventSync ()
> #3 0x0130efe6 in _cfstream_shared_signalEventSync ()
> #4 0x0134297f in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ ()
> #5 0x012a5c39 in __CFRunLoopDoSources0 ()
> #6 0x012a5454 in __CFRunLoopRun ()
> #7 0x012a4db4 in CFRunLoopRunSpecific ()
> #8 0x012a4ccb in CFRunLoopRunInMode ()
> #9 0x01832879 in GSEventRunModal ()
> #10 0x0183293e in GSEventRun ()
> #11 0x003b4a9b in UIApplicationMain ()
> #12 0x00002cd8 in main at /Users/tatd2/Documents/Personal/OpenStreetPad/OpenStreetPad/main.m:17
As you can see, none of that is in my code (beyond main), so I have a real problem debugging what's going on here. What I have noticed is that every time this crash occurs, another thread is currently reading from a stream with this back trace:
> #0 0x92a08c22 in mach_msg_trap ()
> #1 0x92a081f6 in mach_msg ()
> #2 0x0134213a in __CFRunLoopServiceMachPort ()
> #3 0x012a5605 in __CFRunLoopRun ()
> #4 0x012a4db4 in CFRunLoopRunSpecific ()
> #5 0x012a4ccb in CFRunLoopRunInMode ()
> #6 0x01349609 in boundPairRead ()
> #7 0x012ab744 in CFReadStreamRead ()
> #8 0x0133f69f in -[__NSCFInputStream read:maxLength:] ()
> #9 0x00d82da6 in -[NSXMLParser parseFromStream] ()
> #10 0x00d82e2a in -[NSXMLParser parse] ()
> #11 0x0000ea99 in __34-[OSPMapServer popConnectionQueue]_block_invoke_0 ()
> #12 0x01e43445 in _dispatch_call_block_and_release ()
> #13 0x01e44c7b in _dispatch_async_f_redirect_invoke ()
> #14 0x01e444e6 in _dispatch_worker_thread2 ()
> #15 0x98a83b24 in _pthread_wqthread ()
> #16 0x98a856fe in start_wqthread ()
As you can see, up to OSPMapServerMaxSimultaneousConnections operations are dispatched at once to parse the output of an NSURLConnection, notably, if that constant is set to 1, the crash no longer occurs.
> - (void)popConnectionQueue
> {
> @synchronized(self)
> {
> while ([[self currentConnections] count] < OSPMapServerMaxSimultaneousConnections && [[self connectionQueue] count] > 0)
> {
> OSPConnection *rec = [[self connectionQueue] objectAtIndex:0];
> [[self connectionQueue] removeObjectAtIndex:0];
> [[self currentConnections] addObject:rec];
> [rec setConnection:[NSURLConnection connectionWithRequest:[rec request] delegate:rec]];
> [[rec connection] start];
> CFReadStreamRef readStream;
> CFWriteStreamRef writeStream;
> CFStreamCreateBoundPair(NULL, &readStream, &writeStream, 4096);
> NSInputStream *iStream = CFBridgingRelease(readStream);
> NSOutputStream *oStream = CFBridgingRelease(writeStream);
> [oStream setDelegate:rec];
> NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
> [iStream scheduleInRunLoop:runLoop forMode:NSDefaultRunLoopMode];
> [oStream scheduleInRunLoop:runLoop forMode:NSDefaultRunLoopMode];
> [iStream open];
> [oStream open];
> [rec setParserStream:oStream];
> NSXMLParser *parser = [[NSXMLParser alloc] initWithStream:iStream];
> [parser setDelegate:rec];
> [rec setParser:parser];
> dispatch_async(parserQueue, ^()
> {
> [parser parse];
> });
> }
> }
> }
I'm currently stuck even for ways to approach debugging this problem, if anyone has any ideas how I could tackle this, I'd really apreciate it.
If you'd like to take a look at the full source and/or experience the crash for yourself, the full source is at github.com/beelsebob/OpenStreetPad
Thanks all
Tom Davie
if (*ra4 != 0xffc78948) { return false; }
_______________________________________________
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