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#21966621: USAGE OF AUTO_RW_LOCK_READ/WRITE ON ALREADY LOCKED OBJECT CAUSES DEADLOCK
Fault description:
There is an internal fault in pthread that causes a deadlock when mysql_rwlock_rdlock, mysql_rwlock_unlock functions are used in wrong way. The faulty was triggered by calling two time lock function on already locked object, following seqence:
pthread_rwlock_t *x;
...
pthread_rwlock_wrlock(x); // R:0
pthread_rwlock_wrlock(x); // R:EDEADLK
pthread_rwlock_unlock(x);
pthread_rwlock_unlock(x); // Fault - pthread function doesn't check if the x object is still lock, it always decrement the lock-counter which causes an underflow
pthread_rwlock_wrlock(x); // Deadlock - lock counter != 0
The production code wasn't checking the result returned by locking function (EDEADLK, EINVAL) and it still was relasing mutex two times (RAII - destructor in object).
Incorrect behaviour:
The fault occured when pluging doesn't release the srv_session and leaves it to be released be server. When server is releasing the session its using Mutexed_map_thd_srv_session class to opearte on session list. Each method of this class is guarded by rwlock, thus function close_all_sessions_of_plugin_if_any() was calling Mutexed_map_thd_srv_session::do_for_all_matching (locking the mutex) and the callback was removing the session from the list by Mutexed_map_thd_srv_session::remove(second lock). Last call leaves the mutex in invalid state thus next attempt of accesing it will cause a deadlock.
Fix description:
The solution checks in constructor of Auto_rw_lock_read,Auto_rw_lock_write the result code mysql_rwlock_rdlock and if it wasn't locked then corresponding release function in destructor isn't called. The locking result could be also checked with assert to tell alert that the code is working wrongly.
Reviewed-by: [email protected]
RB: 10561
0 commit comments