Issue Details (XML | Word | Printable)

Key: CORE-5843
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Vlad Khorsun
Reporter: Vlad Khorsun
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Firebird Core

Wrong handling of failures of TRANSACTION START trigger

Created: 10/Jun/18 08:47 PM   Updated: 16/Jun/18 09:44 PM
Component/s: Engine
Affects Version/s: 4.0 Alpha 1, 3.0.3
Fix Version/s: 3.0.4, 4.0 Beta 1

File Attachments: 1. File prepare.sql (1 kB)


QA Status: Done successfully


 Description  « Hide
There are two general cases when TRANSACTION START trigger is fired
1. when user start transaction, and
2. when IN AUTONOMOUS TRANSACTION statement starts new transaction.

Let look what happens if TRANSACTION START is present and raises error.

According to documentation (see README.db_triggers.txt):

- TRANSACTION START
Triggers are fired in the newly user created transaction - uncaught
exceptions are returned to the client and the transaction is rolled-back.

In the 1st case new transaction is not rolled-back currently and left active until Firebird process alive.
In the 2nd case new transaction is rolled-back but it also fires TRANSACTION ROLLBACK trigger
which is wrong. Note, in the 1st case TRANSACTION ROLLBACK trigger is not fired.

 All   Comments   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Vlad Khorsun added a comment - 11/Jun/18 03:57 PM
Run prepare.sql to prepare database for testing:
isql <database> -nodbt -i prepare.sql

Vlad Khorsun added a comment - 11/Jun/18 04:00 PM
Test case 1:
isql <database>

SQL> set autoddl off;
SQL> commit;
SQL>
SQL> select mon$transaction_id from mon$transactions; -- one transaction exists

   MON$TRANSACTION_ID
=====================
                  682

SQL> select rdb$set_context('USER_SESSION', 'tx_abort', 1) from rdb$database; -- flag to raise error on next tx start

RDB$SET_CONTEXT
===============
              0

SQL> commit;
SQL> select mon$transaction_id from mon$transactions; -- it start transaction
Statement failed, SQLSTATE = HY000
exception 3
-EX_TRA_START
-transaction 683 aborted
-At trigger 'TX_START' line: 10, col: 5
SQL> commit;
SQL> select mon$transaction_id from mon$transactions;

   MON$TRANSACTION_ID
=====================
                  685
                  683

Note, transaction 683 was aborted but still alive

Vlad Khorsun added a comment - 11/Jun/18 04:04 PM
Test case 2:

SQL>
SQL> set autoddl off;
SQL> commit;
SQL> select rdb$set_context('USER_SESSION', 'tx_trig_log', 'BEGIN') from rdb$database; -- start logging

RDB$SET_CONTEXT
===============
              0

SQL> commit;
SQL>
SQL> select mon$transaction_id from mon$transactions;

   MON$TRANSACTION_ID
=====================
                  691

SQL> execute procedure tx_autonomous;
Statement failed, SQLSTATE = HY000
exception 3
-EX_TRA_START
-transaction 692 aborted
-At trigger 'TX_START' line: 10, col: 5
At procedure 'TX_AUTONOMOUS' line: 4, col: 3
SQL> select rdb$get_context('USER_SESSION', 'tx_trig_log') from rdb$database;

RDB$GET_CONTEXT


===============================================================================
BEGIN
commit 690
start 691
start 692
exception 692
rollback 692

Note: transaction 692 was aborted by TRANSACTION START trigger
but TRANSACTION ROLLBACK trigger was fired.