Giter Site home page Giter Site logo

Comments (6)

Lasombras avatar Lasombras commented on September 26, 2024 1
fun foo() = runBlocking {
        async(Dispatchers.IO) {
            queries.transactionWithResult {
                 //Nothing
            }
        }

        async(Dispatchers.IO) {
            queries.transactionWithResult {
                 //Nothing
            }
        }
}

Just open 2 transactions in async and the driver raise this error.
It's like the driver try to run the transactions in a same thread and open a new transaction inside the first one.

Same with threads, just start 2 transactions in 2 threads, and the driver run the second transaction in the first one.

        thread {
            queries.transactionWithResult { }
        }

        thread {
            queries.transactionWithResult { }
        }
        Thread.sleep(500)

Exception in thread "Thread-6" org.sqlite.SQLiteException: [SQLITE_ERROR] SQL error or missing database (cannot start a transaction within a transaction)

In SQLDelight 2.0.0, to prevent this issue, I used a custom Dispatcher for my database request, limited to one parallelism.

        val databaseDispatcher = Dispatchers.IO.limitedParallelism(1)

        val table1Data = async(databaseDispatcher) { ... } 
        val table2Data = async(databaseDispatcher) { ... } 

But, of course, I break the parallelism of async in this temporary solution. And only one request can run at the same time.
I will return easily to the Dispatcher.IO when the fix will be done.

from sqldelight.

AlecKazakova avatar AlecKazakova commented on September 26, 2024

I'm not sure how this would result in nested transactions, is the method you're calling this from itself in a transaction?

Although SQLDelight does some protection from inner transactions (with the noEnclosing stuff) so that also surprised me. Are you able to make a repro project we can look in to?

from sqldelight.

Nek-12 avatar Nek-12 commented on September 26, 2024

Setting up a repro project would be a lot of work. If I have the free time, I can try to create one. No, the method itself is not in a transaction. This issue is reproduced in roughly 5% calls run

from sqldelight.

Nek-12 avatar Nek-12 commented on September 26, 2024

True, I am also still seeing this happening often still. Thanks, didn't expect the repro to be that simple

from sqldelight.

Nek-12 avatar Nek-12 commented on September 26, 2024

@AlecKazakova may I request this issue to be triaged? There is no more info to add and this issue currently affects a very large portion of our users in production

This issue alone has brought our project below the GP bad behavior threshold already

from sqldelight.

DanielNovak avatar DanielNovak commented on September 26, 2024

It could be also a platform bug, but maybe triggered by SqlDelight. We have seen a similar bug in Room too.
Here is a link to the "platform bug":
https://issuetracker.google.com/issues/37001653

from sqldelight.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.