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

Transaction isn't rolling back after timeout #90

Closed
LeBaur opened this issue Apr 12, 2019 · 1 comment
Closed

Transaction isn't rolling back after timeout #90

LeBaur opened this issue Apr 12, 2019 · 1 comment

Comments

@LeBaur
Copy link

LeBaur commented Apr 12, 2019

I'm building an app using Spring Boot 2.1.3, Atomikos 4.0.6 and Oracle Database 11g. After timeout occurs, transaction doesn't rollback immediately, but instead continues on execution. Can anyone explain if it's the correct behaviour and I don't understand something or am I doing something wrong?

I added spring-boot-starter-jta-atomikos to my pom.xml and configured datasource as follows below. I don't explicitly configure anything else related to database like EntityManager or Hibernate properties. Also, I don't configure UserTransactionManager, UserTransactionImp, UserTransactionService and JtaTransactionManager explicitly. Can any of these be a problem?

@Configuration
public class MasterDbConfig {

    @Primary
    @Bean(initMethod = "init", destroyMethod = "close")
    public AtomikosDataSourceBean masterDataSource() {
        AtomikosDataSourceBean dataSource = new AtomikosDataSourceBean();
        dataSource.setUniqueResourceName("MasterDBXAResource");
        dataSource.setXaDataSourceClassName("oracle.jdbc.xa.client.OracleXADataSource");
        dataSource.setBorrowConnectionTimeout(120);
        dataSource.setMinPoolSize(3);
        dataSource.setMaxPoolSize(30);

        Properties xaProps = new Properties();
        xaProps.put("URL",  "jdbc:oracle:thin:@...:1521:...");
        xaProps.put("user", "...");
        xaProps.put("password", "...");
        dataSource.setXaProperties(xaProps);
 
        return dataSource;
    }
}

I modify the transaction timeout in properties:

spring.jta.atomikos.properties.default-jta-timeout=30000ms

Then I test it using the following method:

@Transactional
@Scheduled(fixedDelay = 300000)
public void test() throws InterruptedException {
    log.info("test() - start");

    Thread.sleep(40000);
    log.info("after sleep");
    Long cnt = testRepository.cntTest();

    log.info("test() - end: cnt = {}", cnt);
}

Then I see the following in the log and I see the query executing in the database:

12-04-2019 12:09:48,985 INFO  (XXX.java:87) - test() - start
12-04-2019 12:10:19,284 WARN  (Slf4jLogger.java:24) - Transaction 10.19.28.18.tm155504938896800002 has timed out and will rollback.
12-04-2019 12:10:28,986 INFO  (XXX.java:91) - after sleep
12-04-2019 12:10:29,083 DEBUG (SqlStatementLogger.java:94) - 
    SELECT
        count(1) 
    FROM
        XXX
    WHERE
        create_date BETWEEN TO_DATE('2018-04-01','YYYY-MM-DD') AND TO_DATE('2019-04-09 23:59:59', 'YYYY-MM-DD HH24:MI:SS')

Why exception is not thrown and execution is not stopped and transaction is not rolled back imemdiately, instead it is stuck like this?

@GuyPardon
Copy link
Contributor

Hi,

We have an option to allow rollback on timeout, but disabled by default because some XA drivers have issues with it (since the rollback happens in a different thread than the one that started it).

The transaction is marked for rollback when it times out. The application should cleanup, and commit will fail with rollback as a result.

If you want to avoid pending DB sessions, make sure to set a queryTimeout on your JDBC statements. You could use the same value as the transaction timeout.

Guy

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

No branches or pull requests

2 participants