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

Wrong handling of failures of TRANSACTION START trigger [CORE5843] #6104

Closed
firebird-issue-importer opened this issue Jun 10, 2018 · 9 comments

Comments

@firebird-issue-importer

Submitted by: @hvlad

Attachments:
prepare.sql

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.

Commits: ceefd57 3ddc20a c48ebfb

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Jun 10, 2018

Modified by: @hvlad

assignee: Vlad Khorsun [ hvlad ]

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Jun 11, 2018

Commented by: @hvlad

Run prepare.sql to prepare database for testing:
isql <database> -nodbt -i prepare.sql

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Jun 11, 2018

Modified by: @hvlad

Attachment: prepare.sql [ 13260 ]

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Jun 11, 2018

Commented by: @hvlad

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

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Jun 11, 2018

Commented by: @hvlad

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.

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Jun 14, 2018

Modified by: @hvlad

status: Open [ 1 ] => Resolved [ 5 ]

resolution: Fixed [ 1 ]

Fix Version: 4.0 Beta 1 [ 10750 ]

Fix Version: 3.0.4 [ 10863 ]

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Jun 14, 2018

Modified by: @hvlad

Version: 3.0.3 [ 10810 ]

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Jun 17, 2018

Modified by: @pavel-zotov

status: Resolved [ 5 ] => Resolved [ 5 ]

QA Status: No test => Done successfully

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Jun 17, 2018

Modified by: @pavel-zotov

status: Resolved [ 5 ] => Closed [ 6 ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment