couchbase-lite-ios: openDatabaseNamed failing with SQLite Code=23 "authorization denied" error

Been experiencing some issues for a few months now related to a very hard to reproduce issue causing my app to not behave properly. Was able to pin-point the issue today to the database failing to open due to an authorization denied SQLite 23 error: Error Domain=SQLite Code=23 "authorization denied" UserInfo={NSLocalizedDescription=authorization denied}

I’ve come across some older posts about it potentially being related to iOS file protection, but nothing conclusive came up so raising the issue here hoping I can get some help to work around it / avoid it.

I found a purported fix on StackOverflow that was supposed to fix it, by switching off the file protection, but the issue is still present. Although I’m not sure whether thats because the fileProtection options are only set when the database is first created or not, or whether the fileProtection stuff doesn’t fix the issue anyway.

fileprivate func createManager(_ queue: DispatchQueue) -> CBLManager?
{
    let writingOptions : NSData.WritingOptions = NSData.WritingOptions.noFileProtection
    let options = CBLManagerOptions(readOnly:false,fileProtection:writingOptions)
    
    let cblpoptions = UnsafeMutablePointer<CBLManagerOptions>.allocate(capacity:1)
    cblpoptions.initialize(to:options)
    
    if let mng = manager { return mng }
    
    do
    {
        let mng = try CBLManager(directory:CBLManager.defaultDirectory(),options:cblpoptions)
        mng.dispatchQueue = queue
        return mng
    }
    catch let error
    {
        log.error("Failed to create cb manager - \(error)")
    }
    return nil
}

fileprivate func createDatabase(_ syncGateway:String) -> CBLDatabase?
{
    let dbName = syncGateway.lastPathComponent
    let options = CBLDatabaseOptions(); options.create = true
    
    if gateway != syncGateway
    {
        do
        {
            try db?.close()
        }
        catch
        {
            log.error("Failed to close cb database")
        }
        db = nil
    }
    
    var database : CBLDatabase? = nil
    
    do
    {
        if db == nil { database = try manager!.openDatabaseNamed(dbName,with:options) }
        else { database = db }
    }
    catch let error
    {
        log.error("Failed to open cb database - \(error)") // Failing here with "Failed to open cb database - Error Domain=SQLite Code=23 "authorization denied" UserInfo={NSLocalizedDescription=authorization denied}"
    }
    
    return database
}

  • Version: 1.3.1
  • Client OS: 10.1.1

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 17 (5 by maintainers)

Most upvoted comments

Hey, I Use version 1.4.0 via pods (objective c) and still receive 10-20k errors daily: “Domain: SQLite Code: 23 NSLocalizedDescription: authorization denied” when call method [[CBLManager sharedInstance] databaseNamed:nameConstant error:&error]; As I see this issue should be fixed in 1.4.0 but it’s still reproduce. Can you help me ?