Skip to content

Using a semaphore could cause a wait forever #101

@evermeer

Description

@evermeer

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
fgates@me.com mailto:fgates@me.com

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions