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

Nested transactions are stuck #925

Open
RicoGit opened this issue Feb 14, 2022 · 3 comments
Open

Nested transactions are stuck #925

RicoGit opened this issue Feb 14, 2022 · 3 comments

Comments

@RicoGit
Copy link

RicoGit commented Feb 14, 2022

I have a test like this:

  test("Finagle StdClient is stuck on nested transaction") {
    val finagleClient: Client with Transactions = getUnderlyingFinagleClient
    val future = finagleClient.transaction { tx1 =>
      for {
        _ <- tx1.execute[Unit](sql"select * from nodes limit 1")
        _ <- finagleClient.transaction { tx2 =>
          tx2.execute(sql"select * from nodes limit 1")
        }
      } yield ()
    }

    intercept[TimeoutException] {
      Await.result(future, Duration.fromSeconds(42)) // always throws timeout exception 
    }
  }

This is minimal example, but it reflects what I actually've faced. I knows that I'm shouldn't do that in general. But in large code base with a bunch of Dao and Repositories is really hard to catch this case.
Is this usage of client valid?Is it a bug?

@joybestourous
Copy link
Contributor

Nested transactions aren't permitted in mysql: https://dev.mysql.com/doc/refman/5.7/en/implicit-commit.html

@RicoGit
Copy link
Author

RicoGit commented Feb 24, 2022

The question is about API of finagle-mysql that allows to make stuff like that.

I'm figured out why it's stuck. The reason is session pool with max size 1. If increase max size of session poll up to N then N number of nested transaction are allowed. In fact all transactions are just parallel and don't share any state.

The second problem is deadlocks. If you update row in parent transaction and then try to update the same row in child transaction they will be wait each other.

I understand that it's difficult to ban expression like above in compile time. But maybe better if nested transactions will be raise some exception in runtime?

@joybestourous
Copy link
Contributor

gotcha, yeah we can make more clear that we don't support nested transactions via the api. to clarify, when you made those changes, you were able to get nested transactions working?

@joybestourous joybestourous reopened this Feb 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants