AFURLConnectionOperation 'start' method is called before it is ready and will never be called again

We use AFNetworking ( https://github.com/AFNetworking/AFNetworking ) in our application and NSOperationStack ( https://github.com/nicklockwood/NSOperationStack ) to establish dependencies so that the last operation takes precedence over the others in the queue (behavior stack). I ran into a problem when the start method for AFURLConnectionOperation is called, but the isReady method returns NO due to dependencies. This immediately leads to a "start". After the very first attempt to start work, the "start" method will never be called again, so the operation never reaches the isFinished state, it is never removed from the queue and, ultimately, operations like this get stuck in the queue. I would be grateful for any thought on this issue. Thanks!

Additional information: none of the operations has been canceled, and I do not see any dependent circles in the queue. We use setLIFODependencyenciesForOperation with an existing operation call that does not change the AFNetworking code: [self.operationQueue setLIFODependencyenciesForOperation: operation];

Update: now, thinking more about this, is it possible to have zero dependencies at some point and have isReady return YES when NSOperationQueue decides that the operation is ready, but by the time it starts (), the number of dependencies is called up by 1 or more.

+1
source share
1 answer

This sounds like a problem with the 'NS'OperationStack Github project you are using.

Changing NSOperation dependencies after adding them to NSOperationQueue in the documentation recommends:

It is important . Before starting your operations or adding them to the operation queue, you should always configure dependencies. Dependencies added subsequently may not interfere with the launch of this operation object. (From: Concurrency Programming Guide: Configuring Interoperability Dependencies)

I think the best approach would be to keep your own LIFO stack out of the operation queue and use the completion of one operation to start the sequence of the next most important operation.

Or, if you don’t need to be strict, perhaps you could use -[NSOperation setPriority:] to prioritize later operations over earlier ones.

+5
source

All Articles