mariadb/storage
Vlad Lesin b54e7b0cea MDEV-31185 rw_trx_hash_t::find() unpins pins too early
rw_trx_hash_t::find() acquires element->mutex, then unpins pins, used for
lf_hash element search. After that the "element" can be deallocated and
reused by some other thread.

If we take a look rw_trx_hash_t::insert()->lf_hash_insert()->lf_alloc_new()
calls, we will not find any element->mutex acquisition, as it was not
initialized yet before it's allocation. rw_trx_hash_t::insert() can reuse
the chunk, unpinned in rw_trx_hash_t::find().

The scenario is the following:

1. Thread 1 have just executed lf_hash_search() in
rw_trx_hash_t::find(), but have not acquired element->mutex yet.
2. Thread 2 have removed the element from hash table with
rw_trx_hash_t::erase() call.
3. Thread 1 acquired element->mutex and unpinned pin 2 pin with
lf_hash_search_unpin(pins) call.
4. Some thread purged memory of the element.
5. Thread 3 reused the memory for the element, filled element->id,
element->trx.
6. Thread 1 crashes with failed "DBUG_ASSERT(trx_id == trx->id)"
assertion.

Note that trx_t objects are also reused, see the code around trx_pools
for details.

The fix is to invoke "lf_hash_search_unpin(pins);" after element->trx is
stored in local variable in rw_trx_hash_t::find().

Reviewed by: Nikita Malyavin, Marko Mäkelä.
2023-05-19 15:50:20 +03:00
..
archive Apply clang-tidy to remove empty constructors / destructors 2023-02-09 16:09:08 +02:00
blackhole Apply clang-tidy to remove empty constructors / destructors 2023-02-09 16:09:08 +02:00
cassandra Merge 10.3 into 10.4 2021-11-29 10:59:22 +02:00
connect Ensure that source files contain only valid UTF8 encodings (#2188) 2023-05-19 13:21:34 +01:00
csv Merge branch 'bb-10.3-release' into bb-10.4-release 2021-02-12 17:44:22 +01:00
example Apply clang-tidy to remove empty constructors / destructors 2023-02-09 16:09:08 +02:00
federated Apply clang-tidy to remove empty constructors / destructors 2023-02-09 16:09:08 +02:00
federatedx Apply clang-tidy to remove empty constructors / destructors 2023-02-09 16:09:08 +02:00
heap Apply clang-tidy to remove empty constructors / destructors 2023-02-09 16:09:08 +02:00
innobase MDEV-31185 rw_trx_hash_t::find() unpins pins too early 2023-05-19 15:50:20 +03:00
maria MDEV-28054 Various crashes upon INSERT/UPDATE after changing Aria settings 2023-05-02 23:37:10 +03:00
mroonga Apply clang-tidy to remove empty constructors / destructors 2023-02-09 16:09:08 +02:00
myisam MDEV-28054 Various crashes upon INSERT/UPDATE after changing Aria settings 2023-05-02 23:37:10 +03:00
myisammrg Merge branch '10.3' into 10.4 2020-08-03 14:44:06 +02:00
oqgraph Merge 10.3 into 10.4 2021-11-29 10:59:22 +02:00
perfschema MDEV-29091: Correct event_name in PFS for wait caused by FOR UPDATE 2023-02-15 14:36:05 +00:00
rocksdb MDEV-31057 rocksdb does not compile with gcc-13 2023-05-04 16:07:44 +02:00
sequence Apply clang-tidy to remove empty constructors / destructors 2023-02-09 16:09:08 +02:00
sphinx Merge branch '10.3' into 10.4 2022-10-26 14:55:47 +02:00
spider Merge branch '10.3' into 10.4 2023-04-21 09:10:58 +02:00
test_sql_discovery MDEV-29446 Change SHOW CREATE TABLE to display default collation 2022-09-12 22:10:39 +04:00
tokudb ensure that STRING_WITH_LEN is only used with string literals 2023-04-01 22:31:30 +02:00