Bug #95181 The bugfix for Bug#28511326 seems incorrect
Submitted: 29 Apr 10:02 Modified: 2 May 14:20
Reporter: Jie Zhou Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Logging Severity:S3 (Non-critical)
Version:5.7, 8.0 OS:Any
Assigned to: CPU Architecture:Any

[29 Apr 10:02] Jie Zhou
Description:
Bugfix for "Bug#28511326: DEADLOCK DURING PURGE_LOGS_BEFORE_DATE" solves a deadlock problem by changing the lock from LOCK_log to LOCK_slave_trans_dep_tracker in global variable binlog_transaction_dependency_tracking.
But it seems introduce another problem:
Thread 1:
set global binlog_transaction_dependency_tracking=WRITESET
It acquires LOCK_slave_trans_dep_tracker
invokes Transaction_dependency_tracker::tracking_mode_changed
             ->Writeset_trx_dependency_tracker::rotate
             ->m_writeset_history.clear();
Thread 2:
commit a transaction
It acquires LOCK_log
invokes MYSQL_BIN_LOG::write_gtid
             -> ... -> Writeset_trx_dependency_tracker::get_dependency
             -> m_writeset_history.find, m_writeset_history.insert...

Before Bug#28511326, m_writeset_history is protected by LOCK_log.
After Bug#28511326, m_writeset_history, which is a std::map, has no protection from concurrent access.

How to repeat:
Just analyze from the code...

Suggested fix:
Lock LOCK_slave_trans_dep_tracker in function Writeset_trx_dependency_tracker::get_dependency.
[2 May 14:20] Sinisa Milivojevic
Hi Jie,

I fully agree with your code analysis.

Verified as reported.