Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issues with not cancelling block operations properly #302

Merged
merged 1 commit into from
Jan 11, 2017

Conversation

psahgal
Copy link

@psahgal psahgal commented Jan 4, 2017

I was noticing some issues where the library sometimes spawns a lot of extra threads (around 100 threads). I tracked down the issue to the way the library uses BlockOperation. While the library calls code calls cancelAllOperations, the code within the block operations doesn't check the isCancelled flag during execution. This is incorrect, based on Apple's documentation on OperationQueue:

Canceling an operation object leaves the object in the queue but notifies the object that it should abort its task as quickly as possible. For currently executing operations, this means that the operation object’s work code must check the cancellation state, stop what it is doing, and mark itself as finished.

As a result, the block operations weren't cancelling properly. To fix the issue, I revised the use of BlockOperation so that the code checks the isCancelled flag at appropriate times, such as in while loops.

I should also note that I was having trouble with running the tests, as stated in issue #297. Let me know if there's any test failures.

@daltoniam Please review.

@daltoniam
Copy link
Owner

Nice write up! Thanks for this. I ran it through the tests as well and all appears well. Thanks again.

@daltoniam daltoniam merged commit 33a4551 into daltoniam:master Jan 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants