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

Improve cleanup of inactive transactions from threadLocal when no end() used #1347

Closed
rbygrave opened this issue Mar 12, 2018 · 0 comments
Closed
Assignees
Labels
Milestone

Comments

@rbygrave
Copy link
Member

So when we miss off a transaction.end() the thread local state holds an inactive transaction. This isn't a problem people will generally notice as inactive transactions are handled when the next transaction occurs.

However, we can do better and cleanup the threadLocal state on both commit() / rollback() as well as end().

Steps to reproduce

    Transaction txn1 = server().beginTransaction();
    try {
      txn1.commit();
    } finally {
      // accidentally omit end()
      //txn1.end();
    }

    // internal check on thread local status ... application code doesn't do this
    SpiTransaction txn2 = DefaultTransactionThreadLocal.get("h2");
    assertThat(txn2).isNull();

So with this change Ebean will perform a cleanup of transaction scope on commit() / rollback() ... and also on end() - and will perform the cleanup once so usually on commit() and rollback().

Internals note that ScopedTransaction handles nesting transactions so we really only do the scope cleanup when we are back at the top (no nested transactions to pop).

@rbygrave rbygrave added the bug label Mar 12, 2018
@rbygrave rbygrave added this to the 11.15.1 milestone Mar 12, 2018
@rbygrave rbygrave self-assigned this Mar 12, 2018
rbygrave added a commit that referenced this issue Mar 12, 2018
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

1 participant