• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
iOS deadlocks calling queue-based URL connection delegate
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

iOS deadlocks calling queue-based URL connection delegate


  • Subject: iOS deadlocks calling queue-based URL connection delegate
  • From: Jens Alfke <email@hidden>
  • Date: Wed, 21 Mar 2012 11:51:47 -0700

After changing my NSURLConnection client code to use operation queues instead of runloop-based delegate calls, I'm running into a repeatable deadlock; but only on iOS (5.1, including the simulator), not Mac OS X 10.7.3.

    _connection = [[NSURLConnection alloc] initWithRequest: _request delegate: self
                                          startImmediately: NO];
    [_connection setDelegateQueue: [NSOperationQueue currentQueue]];
    [_connection start];

The main thread then hangs forever while attempting to call the delegate. (See backtrace below.) What I think happens is that it makes a block to call the delegate method, pushes that block onto the queue as an operation, and then waits for it to finish; but the main thread’s operation queue is sequential and already invoked, so it will never get to that operation until the current one finishes.

I’m kind of mystified why this doesn’t happen on Mac OS. Is the delegate dispatching code different on the two platforms?

And how should I work around this? Should I avoid setting the delegate queue when on the main thread? Any other special-case gotchas like this I should know about? :/

—Jens

(gdb) bt
#0  0x972cb83e in __psynch_cvwait ()
#1  0x90a25e21 in _pthread_cond_wait ()
#2  0x909d642c in pthread_cond_wait$UNIX2003 ()
#3  0x00bea8ec in -[__NSOperationInternal waitUntilFinished] ()
#4  0x00bea84e in -[NSOperation waitUntilFinished] ()
#5  0x00c9fefe in -[NSURLConnectionInternalConnection invokeForDelegate:] ()
#6  0x00c9ee3f in -[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:] ()
#7  0x00c9efc5 in -[NSURLConnectionInternal _withActiveConnectionAndDelegate:] ()
#8  0x00be35bb in _NSURLConnectionDidReceiveResponse ()
#9  0x03d39887 in URLConnectionClient::_clientSendDidReceiveResponse ()
#10 0x03e07710 in URLConnectionClient::ClientConnectionEventQueue::processAllEventsAndConsumePayload ()
#11 0x03e07861 in URLConnectionClient::ClientConnectionEventQueue::processAllEventsAndConsumePayload ()
#12 0x03d31120 in URLConnectionClient::processEvents ()
#13 0x03e07117 in non-virtual thunk to URLConnectionInstanceData::multiplexerClientPerform() ()
#14 0x03d30fbf in MultiplexerSource::perform ()
#15 0x0123894f in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ ()
#16 0x0119bb43 in __CFRunLoopDoSources0 ()
#17 0x0119b424 in __CFRunLoopRun ()
#18 0x0119ad84 in CFRunLoopRunSpecific ()
#19 0x0119ac9b in CFRunLoopRunInMode ()
#20 0x00be340f in -[NSRunLoop(NSRunLoop) runMode:beforeDate:] ()
#21 0x00080ed8 in Test_TDMultipartDownloader () at /Volumes/HardDisk/Couchbase/TouchDB/Source/TDMultipartDownloader.m:280
#22 0x000664a6 in RunTestCase (test=0xed904) at /Volumes/HardDisk/Couchbase/TouchDB/vendor/MYUtilities/Test.m:53
#23 0x00066983 in RunTestCases (argc=11, argv=0xbffff5bc) at /Volumes/HardDisk/Couchbase/TouchDB/vendor/MYUtilities/Test.m:128
#24 0x00002b6e in main (argc=11, argv=0xbffff5bc) at /Volumes/HardDisk/Couchbase/TouchDB/Demo-iOS/main.m:17
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: How do I use NSStream with dispatch queues?
  • Next by Date: Now URL connection delegate isn't called at all
  • Previous by thread: Re: How do I use NSStream with dispatch queues?
  • Next by thread: Re: iOS deadlocks calling queue-based URL connection delegate
  • Index(es):
    • Date
    • Thread