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

"Unable to enlist in transaction, a local transaction already exists" in multithreaded environments [DNET833] #768

Open
firebird-automations opened this issue Jul 5, 2018 · 0 comments

Comments

@firebird-automations
Copy link

Submitted by: Daniel H (daniel90)

Votes: 1

We are developing an http://ASP.NET Core (.NET Core Version 2.1.1) web application.
We are using a Firebird 3 Connection Pool with the following options in the connection string:

- Pooling: True
- MinPoolSize: 0
- MaxPoolSize: 50
- Auto_Commit: false
- Enlist: true

On serveral occasions we receive the following exception:
"Unable to enlist in transaction, a local transaction already exists".

This happens in our minimal breaking exampple, if we call the following code with a few threads over HTTP GET:

    \[HttpGet\]
    public async Task<IActionResult\> GetX\(\)
    \{
        IEnumerable<string\> x= null;
        using \(var ts = new TransactionScope\( TransactionScopeAsyncFlowOption\.Enabled\)\)
        \{
            using \(var connection = new FbConnection\(connectionString\)\)
            \{
                roles = await connection\.QueryAsync<string\>\(
                    sql: "SELECT strField FROM X",
                    commandType: CommandType\.Text\);
            \}
            ts\.Complete\(\);
        \}
        return Ok\(x\);
    \}

If we encapsulate the TransactionScope block with a Semaphore it runs fine.
Therefore the question: Does this library supporting multithreading or do we need to protect Firebird calls with a semaphore?

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

No branches or pull requests

2 participants