IDEMPIERE-644 Transaction timeout with long runnig process

This commit is contained in:
Carlos Ruiz 2015-01-13 08:58:04 -05:00
parent b9bfc63cec
commit 9e343a0ec4
2 changed files with 35 additions and 3 deletions

View File

@ -2399,8 +2399,10 @@ public final class DB
private static void verifyTrx(String trxName, String sql) {
if (trxName != null && Trx.get(trxName, false) == null) {
// Using a trx that was previously closed or never opened
// this is equivalent to commit without trx (autocommit)
log.severe("Transaction closed or never opened ("+trxName+") => this is equivalent to commit without trx (autocommit) --> " + sql); // severe?
// probably timed out - throw Exception (IDEMPIERE-644)
String msg = "Transaction closed or never opened ("+trxName+") => (maybe timed out)";
log.severe(msg); // severe
throw new DBException(msg);
}
}

View File

@ -405,6 +405,36 @@ public class Trx
}
/**
* Rollback and End Transaction, Close Connection and Throws an Exception
* @return true if success
*/
public synchronized boolean rollbackAndCloseOnTimeout() {
s_cache.remove(getTrxName());
//local
if (m_connection == null)
return true;
if (isActive())
rollback();
// Close Connection
try
{
m_connection.close();
m_connection = null;
m_active = false;
fireAfterCloseEvent();
}
catch (SQLException e)
{
log.log(Level.SEVERE, m_trxName, e);
}
log.config(m_trxName);
return true;
}
/**
* End Transaction and Close Connection
* @return true if success
@ -651,7 +681,7 @@ public class Trx
if (since > trxs[i].getTimeout() * 1000)
{
trxs[i].log.log(Level.WARNING, "Transaction timeout. Name="+trxs[i].getTrxName() + ", timeout(sec)="+(since / 1000));
trxs[i].close();
trxs[i].rollbackAndCloseOnTimeout();
}
}
}