SQLite.swift icon indicating copy to clipboard operation
SQLite.swift copied to clipboard

Crashes when Calling Sync on a DispatchQueue in a Transaction with a Statement Inside

Open ghost opened this issue 5 years ago • 3 comments

If you call sync on a DispatchQueue (and run a statement inside the closure) inside of a transaction, SQLite.swift will have called sync twice on the same DispatchQueue and therefore crash the program.

Internally, SQLite.swift checks the current executing DispatchQueue to find if it contains a context value made out of the bits of the Connection to figure out if it should call sync on it or not. Sync being called on a DispatchQueue changes out the queue associated with the current execution context, but continues running code on the same call stack.

func test() {
    let connection = try! Connection()
    
    let dispatchQueue = DispatchQueue(label: "Test")
    
    try! connection.transaction {
        dispatchQueue.sync {
            // Crash
            try! connection.execute(".")
        }
    }
    
    let wait = 1 + 1
}

ghost avatar May 20 '19 14:05 ghost

I also see this in my crash logs stack trace when I submitted my app on App Store and they reviewed it. Please shed some light on this issue.

vincekinyops avatar May 22 '19 02:05 vincekinyops

Any news on this? I saw something some crash logs that brought me here and it might be related

nobre84 avatar Oct 09 '19 16:10 nobre84

Related: #813, #365, #259

jberkel avatar Aug 25 '21 08:08 jberkel