Are they rolled back immediately? Are they rolled back after some period of time? Are they left in an uncommitted state?
Is the behavior the same if connection pooling is used and the connections are simply reset?
As long as you don't COMMIT or ROLLBACK a transaction, it's still "running" and potentially holding locks. If your client (application or user) closes the connection to the database before committing, any still running transactions will be rolled back and terminated.
A user disconnects from Oracle Database. The current transaction is committed. A user process terminates abnormally. The current transaction is rolled back.
By default, in all app server and oracle db, autocommit is true. No matter you use connection pooling or direct connection[DriverManager] since commit is the operation on connection object it doesn't matter.
The easiest way is to check if there are any transactions is select * from gv$transaction. This query shows any open transactions in your Oracle system.
It can stay open while connection pooling applies. Example: command timeout can leave locks and TXN because the client sends as "abort".
2 solutions:
Test in the client, literally:
IF @@TRANCOUNT <> 0 ROLLBACK TRAN
Use SET XACT_ABORT ON
to ensured a TXN is cleaned up: Question 1 and Question 2
I always use SET XACT_ABORT ON
.
From this SQL Team blog:
Note that with connection pooling, simply closing the connection without a rollback will only return the connection to the pool and the transaction will remain open until later reused or removed from the pool. This can result in locks begin held unnecessary and cause other timeouts and rolling block
From MSDN, section "Transaction Support" (my bold)
When a connection is closed, it is released back into the pool and into the appropriate subdivision based on its transaction context. Therefore, you can close the connection without generating an error, even though a distributed transaction is still pending. This allows you to commit or abort the distributed transaction at a later time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With