EVCloudKitDao icon indicating copy to clipboard operation
EVCloudKitDao copied to clipboard

Using a semaphore could cause a wait forever

Open evermeer opened this issue 6 years ago • 0 comments

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]

evermeer avatar Apr 13 '18 04:04 evermeer