[MDEV-26558] A cyclic order on lock acquisitions (possibly resulting a deadlock) Created: 2021-09-07  Updated: 2021-11-24  Resolved: 2021-11-24

Status: Closed
Project: MariaDB Server
Component/s: Backup
Affects Version/s: 10.6.4
Fix Version/s: 10.8.0, 10.2.42, 10.3.33, 10.4.23, 10.5.14, 10.6.6, 10.7.2

Type: Bug Priority: Major
Reporter: Ryan Assignee: Robert Bindar
Resolution: Fixed Votes: 0
Labels: None
Environment:

All



 Description   

Hi, developers, thank you for your checking. It seems there is a (potential) deadlock bug in the below code. The function extract_worker_thread_func is not thread-safe, because there is a cyclic acquisition order between the ctxt->mutex and entry->mutex.

{color:#DE350B}extract_worker_thread_func(void *arg)
{
	
	while (1) {
		pthread_mutex_lock(ctxt->mutex);
		...;
 
		pthread_mutex_lock(&entry->mutex);  //ctxt->mutex-->entry->mutex
 
		pthread_mutex_unlock(ctxt->mutex);
    ...;
		
		if (chunk.type == XB_CHUNK_TYPE_EOF) {
			pthread_mutex_lock(ctxt->mutex); // entry->mutex-> ctxt->mutex
			pthread_mutex_unlock(&entry->mutex);
			my_hash_delete(ctxt->filehash, (uchar *) entry);
			pthread_mutex_unlock(ctxt->mutex);
 
			continue;
		}
    ...;
		pthread_mutex_unlock(&entry->mutex);
	}
}{color}

https://github.com/MariaDB/server/blob/76f4a78ba2639b5abd01a88b24a3c509c11530ce/extra/mariabackup/xbstream.cc#L381-L478



 Comments   
Comment by Robert Bindar [ 2021-11-24 ]

Merged Ryan's contribution from github.

Generated at Thu Feb 08 09:46:13 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.