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

App crashes while doing background database operations #1042

Closed
crspybits opened this issue Mar 13, 2021 · 3 comments
Closed

App crashes while doing background database operations #1042

crspybits opened this issue Mar 13, 2021 · 3 comments

Comments

@crspybits
Copy link

Build Information

  • Include the SQLite.swift version, commit or branch experiencing the issue.
    0.12.2

  • Mention Xcode and OS X versions affected.
    iOS 14, Xcode 12.4

  • How do do you integrate SQLite.swift in your project?

  • Swift Package manager

I am deploying test builds of my app on TestFlight. The app is designed to use background URLSession's to do uploading/downloading from a server while the app is in the background.

I'm fairly regularly getting crashes of the app when it goes into the background. Crash reports in Xcode are indicating this is occurring in SQLite code. Here are two examples:

Screen Shot 2021-03-13 at 12 42 17 PM

Screen Shot 2021-03-13 at 12 42 44 PM

I have taken the step of removing security access on the file being used by the database:

extension URL {
    func enableAccessInBackground() {
        /* By default, the NSFileProtectionKey is NSFileProtectionCompleteUntilFirstUserAuthentication and I think this is causing app crashes when it goes into the background.
         */
        let attributes = [ FileAttributeKey.protectionKey : FileProtectionType.none ]
        do {
            try FileManager.default.setAttributes(attributes, ofItemAtPath: path)
            let attr = try FileManager.default.attributesOfItem(atPath: path)
            logger.debug("SQLite db: attr: \(attr)")
        } catch let error {
            logger.error("\(error)")
        }
    }
}

Any ideas?

@crspybits
Copy link
Author

Searching for this issue, I'm finding others recommend not keeping your SQLite database in a shared group container. Which is something I'm doing. See:
https://inessential.com/2020/02/13/how_we_fixed_the_dreaded_0xdead10cc_cras

@crspybits
Copy link
Author

I'm wondering why the Connection constructor doesn't let you pass flags. E.g., it seems important that I be able to pass the flag SQLITE_OPEN_FILEPROTECTION_NONE.

@jberkel
Copy link
Collaborator

jberkel commented Aug 24, 2021

@crspybits so looks like there's not much which can be done on the library side? (other than adding this information to the documentation).

regarding your last point (pass flags for opening), that sounds like a good suggestion, we should open a separate issue for this.

@jberkel jberkel added this to the 0.14.0 milestone Jul 19, 2022
jberkel added a commit that referenced this issue Oct 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants