Bug #32970 Locking thread not added to process list properly
Submitted: 4 Dec 2007 17:28 Modified: 26 Feb 2008 1:39
Reporter: Chuck Bell Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Backup Severity:S3 (Non-critical)
Version:6.0 OS:Any
Assigned to: Chuck Bell CPU Architecture:Any

[4 Dec 2007 17:28] Chuck Bell
Description:
The backup locking thread in be_thread.cc is not added correctly to the list of processes when the command SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST; is issued. In fact, the fill_schema_processlist() method in sql_show.cc @1839 will fail randomly with the following (or similar) error:

master.err: main.backup_ddl_blocker: safe_mutex: Trying to lock unitialized mutex at sql_show.cc, line 1839

The cause is a race condition between the locking thread startup and the show method. If the show method accesses the thread before it has completed its setup, the above error will result from the show command trying to lock the uninitialized mutex.

How to repeat:
Replace this code in create_new_thd() in be_thread.cc and run the backup_ddl_blocker test multiple times. It will eventually fail on most Linux machines (but not on Windows -- see my_thr_init() for details).

===== be_thread.cc 1.2 vs edited =====
--- 1.2/sql/backup/be_thread.cc	2007-11-28 22:13:08 -05:00
+++ edited/be_thread.cc	2007-12-04 11:14:40 -05:00
@@ -73,13 +73,6 @@
   thd->main_security_ctx.master_access= ~0;
   thd->main_security_ctx.priv_user= 0;
   thd->real_id= pthread_self();
-  /*
-    Making this thread visible to SHOW PROCESSLIST is useful for
-    troubleshooting a backup job (why does it stall etc).
-  */
-  pthread_mutex_lock(&LOCK_thread_count);
-  threads.append(thd);
-  pthread_mutex_unlock(&LOCK_thread_count);
   lex_start(thd);
   mysql_reset_thd_for_next_command(thd);
   DBUG_RETURN(thd);

Suggested fix:
Examine the locking thread setup and create methods to ensure the proper sequence is followed and that the thread is added to the global thread list with the proper attributes assigned with valid values.
[17 Dec 2007 23:26] Chuck Bell
Original code was correct but required additional code to allow thread to show in processlist. Patch forthcoming.
[18 Dec 2007 22:32] Chuck Bell
Patch ready for review. See http://lists.mysql.com/commits/40163.
[19 Dec 2007 15:37] Chuck Bell
Problem found in patch corrected. See new patch http://lists.mysql.com/commits/40212 .
[30 Jan 2008 22:38] Rafal Somla
Good to push.
[31 Jan 2008 4:47] Chuck Bell
Patch queued.
[25 Feb 2008 20:19] Bugs System
Pushed into 6.0.5-alpha
[26 Feb 2008 1:39] Paul DuBois
Noted in 6.0.5 changelog.

The Online Backup locking thread did not show up in the
server's process list information due to a race condition.
[14 Mar 2008 1:32] Paul DuBois
Correction: No changelog entry needed; this bug did not appear in any released version.