Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-26558

A cyclic order on lock acquisitions (possibly resulting a deadlock)

    XMLWordPrintable

    Details

      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

        Attachments

          Activity

            People

            Assignee:
            robertbindar Robert Bindar
            Reporter:
            Ryan Ryan
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Git Integration