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

"evaluateConditions() was called out-of-order" assert in Operation.swift is sometimes failing #71

Open
therauli opened this issue Jul 28, 2016 · 2 comments

Comments

@therauli
Copy link

I have a rather big code base that was using the the code based on the the WWDC presentation code. I recently discovered PSOperations and updated our code base using that. Now for some reason the assert in Operation class evaluateConditions is failing when my operation inherited form GroupOperation gets cancelled.

I'm puzzled since the failure occurs rarely. The code base uses Operations and especially GroupOperatins heavily in down loading and parsing data from REST sources.

Why am I getting the assertion failure?

I'm using code from master (latest commit is 7947757)

@mcmurrym
Copy link
Contributor

We have made many changes around race conditions, are you seeing this problem with the latest version?

@DmitrijMaz
Copy link

I have encountered this issue as well and i have found a 100% reproducible case.

  1. Create a condition that is async (do a dispatch after 1 second and call completion with any result)
  2. Add the operation with that condition to queue and cancel immediately
  3. The operation will crash in debug build due to this assert, since the var isReady: Bool is returning true when the operation is cancelled, but state at this point is still .evaluatingConditions

What i did to fix this:

// Here is where we extend our definition of "readiness".
    override open var isReady: Bool {
        stateAccess.lock()
        defer { stateAccess.unlock() }

        guard super.isReady else { return false }

        guard !isCancelled else {
            // when operation gets cancelled during evaluate conditions an assert is raised, so prevent transition to `isReady` until conditions are finished evaluating since there's no cancellation of conditions
            return state != .evaluatingConditions
        }

        switch state {
        case .initialized, .evaluatingConditions, .pending:
            return false
        case .ready, .executing, .finishing, .finished:
            return true
        }
    }

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

No branches or pull requests

3 participants