Record implementation works fine in debug and unit tests, crashes hard in Ad Hoc builds

I'm fairly stuck trying to understand this issue.

I've got a very simple database with very simple PersistableRecords and a generic BaseStore which defines fetchAll as follows:

   func fetchAll() -> [T.DomainModel] {
        var result = [T.DomainModel]()
        do {
            try dbQueue.read { db in
                let storeResources = try T.fetchAll(db)
                result = storeResources.map { $0.toDomainModel() } 
            }
            // catch block removed for brevity
        }
        return result
    }

Works perfectly when running as debug. Exhaustive unit tests exercise this over and over and it all works exactly as anticipated. However, when we push to TestFlight or load an AdHoc build, the app crashes when fetchAll is executed for any table.

The crash appears to be in DatabaseValueConvertible:289 if sqlite3_column_type(sqliteStatement, index) == SQLITE_NULL {

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x04b004b000000009 -> 0xffffffb000000009 (possible pointer authentication failure)

Any ideas about things to try or possible solutions?

Hello @eBurns,

I'm clueless :-) My advice is to make the crash reproducible, and gather more information:

  1. Run or test your app in the Release configuration. It will make it closer to the TestFlight and AdHoc builds, and we have a good chance to reproduce the issue. You change the configuration with the "Edit Scheme" Xcode command. Generally speaking, try hard to reproduce the crash.
  2. When you are able to reproduce the crash on your machine, grab more information, and open an issue on Github. For example, grab a detailed stack trace with the bt command in the debugger. Remember to provide all information requested by the issue template.

Thanks for the quick reply. Been chasing this all day and I found that if I turn optimization off, everything works great.

Still trying to find a way around this (with optimization enabled).

Just wanted to post an update here. This is an odd conflict between sql versions. I'm including the SQLCipher cocoapod, and it works great before optimization. I knew there was another library that used sqlite, but we removed it from that lib and the issue persisted.

After lots of testing and failures, we finally figured out that two other cocoapods in use include sqlite which confuses the optmization process.

There is a little insight here:


Although I did not see any of the errors mentioned and none of those fixes worked for me.

Part of the confusion was the nature of the errors. Sometimes it would just be a EXC_BAD_ACCESS. Othertimes, the issue would be parsing PersistableRecords - it couldn't figure out the type and would say something like "Cannot intrinsically convert 222 to Int64".

My fix was to add -framework "SQLCipher" before $(inherited) to Other Linker Flags. This seems to make that library primary and none of it is optimized away.

Hope my pain can help someone else...

Thanks for the feedback, Ed. You're not the first one facing issues when both SQLite and SQLCipher are linked into your app. It's actually a recurring problem, but I have to definitive answer to it.