Skip to content

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

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

Open
ghost opened this issue May 20, 2019 · 3 comments
Labels

Comments

@ghost
Copy link

ghost commented May 20, 2019

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
}
@vincekinyops
Copy link

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.

@nobre84
Copy link

nobre84 commented Oct 9, 2019

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

@jberkel
Copy link
Collaborator

jberkel commented Aug 25, 2021

Related: #813, #365, #259

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants