You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bug#35277407 InnoDB:trx hangs due to wrong trx->in_innodb value
This commit backports the fix to 8.0
This patch will solve the following duplicates of this bug:
Bug #112425: trx_t might be Use-After-Free in innobase_commit_by_xid
Bug #99643: innobase_commit_by_xid/innobase_rollback_by_xid is not
thread safe
Bug #105036: trx would be used after free in `innobase_commit_by_xid`
and rollback
Background:
TrxInInnoDB is a RAII wrapper for trx_t object used to track if the
transaction's thread is currently executing within InnoDB code. It is
acquired on all entry points, and as Innodb can be entered "recursively",
the trx->in_depth is used to track the balance of enters and exits.
On the outermost enter, the thread additionally checks if
trx->in_innodb has the TRX_FORCE_ROLLBACK (0x8000 0000) flag set, which
means a high priority transaction is attempting an asynchronous rollback
of this transaction, so to avoid races, this thread should wait for the
rollback to complete.
Issue:
TrxInInnoDB's destructor calls exit which resets in_depth and
in_innodb increased by enter. However innobase_commit_by_xid and
innobase_rollback_by_xid calls trx_free_for_background which returns the
trx back to the pool, before the destructor is called. If this trx is
being reused by another thread, it can lead to data-race and corrupted
value of in_depth and in_innodb. If in_depth gets the value of -1,
subsequent calls to enter and exit will bump in_innodb by one. This can
lead to indefinite wait if in_innodb reaches TRX_FORCE_ROLLBACK.
Fix:
Ensure that TrxInInnoDB calls exit before returning the trx object to
the pool. Further add checks to catch corrupt values of in_depth when
freeing trx. Trx state validation before free was missed in
trx_free_prepared_or_active_recovered
Thanks to Shaohua Wang (Alibaba, Ex-Innodb) for the contribution
Change-Id: Ibf79bec85ffa0eaf65f565c169db61536bff10a2
0 commit comments