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

Using a semaphore could cause a wait forever #101

Open
evermeer opened this issue Apr 13, 2018 · 0 comments
Open

Using a semaphore could cause a wait forever #101

evermeer opened this issue Apr 13, 2018 · 0 comments

Comments

@evermeer
Copy link
Owner

Reported by Joseph Gates:

Hi,

Now running with

Using EVCloudKitDao (3.5.1)
Using EVReflection (5.6.0)

Testing worked fine with XCTAssertNotNil et al. Thanks for your help!

I did find another issue. You may want me to add it to the issue tracker for EVCloudKitDao.

What happens is that the app fails to complete start up. I tracked it to this in EVCloudKitDao.swift

/**
Set or reset the quick reference to the container and database

- parameter containerIdentifier: Passing on the name of the container
*/
open func initializeDatabase(_ containerIdentifier: String? = nil) {
    let pathDir = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true)
    if pathDir.count > 0 {
        fileDirectory = pathDir[0] as NSString!
    } else {
        fileDirectory = ""
    }
    filemanager = FileManager.default
    ioQueue = DispatchQueue(label: "NL.EVICT.CloudKit.ioQueue", attributes: []) as DispatchQueue

    if let identifier = containerIdentifier {
        container = CKContainer(identifier: identifier)
    } else {
        container = CKContainer.default()
    }
    if self.isType == .isPublic {
        database = container.publicCloudDatabase
    } else {
        database = container.privateCloudDatabase
    }

    let sema = DispatchSemaphore(value: 0)
    container.accountStatus(completionHandler: {status, error in
        if error != nil {
            EVLog("Error: Initialising EVCloudKitDao - accountStatusWithCompletionHandler.\n\(error!.localizedDescription)")
        } else {
            self.accountStatus = status
        }
        EVLog("Account status = \(status.hashValue) (0=CouldNotDetermine/1=Available/2=Restricted/3=NoAccount)")
        sema.signal()
    })

// let _ = sema.wait(timeout: DispatchTime.distantFuture) //???!!!
EVLog("Container identifier = (container.containerIdentifier.debugDescription)")
}

The second to last statement is
let _ = sema.wait(timeout: DispatchTime.distantFuture) //???!!!

It waits on the semaphore forever. I commented it out and everything runs as expected. Any suggestions on what I might have or have not done that would cause the wait forever? I’m sure that your other users would have reported this before now if it were a common mistake. I checked the open/closed issues bur haven’t seen anything related.

Let me know how I can help, and thanks again for your help,

Joseph Gates
[email protected] mailto:[email protected]

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

1 participant