Bug #62055 Race condition in check_temp_dir() from multiple mysqld instances
Submitted: 2 Aug 2011 10:24 Modified: 19 Dec 2011 1:29
Reporter: Yoshinori Matsunobu (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Replication Severity:S3 (Non-critical)
Version:5.1.59, 5.5.15 OS:Any
Assigned to: CPU Architecture:Any

[2 Aug 2011 10:24] Yoshinori Matsunobu
Description:
In check_temp_dir(), mysqld creates a temporary file and removes it immediately, without protecting any mutex/lockfile/etc. 
--------------
  /*
    Check if the directory exists.
   */
  if (!(dirp=my_dir(tmp_dir,MYF(MY_WME))))
    DBUG_RETURN(1);
  my_dirend(dirp);

  /*
    Check permissions to create a file.
   */
  if ((fd= mysql_file_create(key_file_misc,
                             tmp_file, CREATE_MODE,
                             O_WRONLY | O_BINARY | O_EXCL | O_NOFOLLOW,
                             MYF(MY_WME))) < 0)
  DBUG_RETURN(1);

  /*
    Clean up.
   */
  mysql_file_close(fd, MYF(0));
--------------

check_temp_dir() is called at initializing SQL thread. 
  if (check_temp_dir(rli->slave_patternload_file))
The filename is fixed to SQL_LOAD-.

A problem might happen when multiple mysqld instances on the same host start SQL thread at the same time. SQL thread might abort with the following error.

110802 00:00:00 [ERROR] Slave SQL: Unable to use slave's temporary directory /tmp - Can't create/write to file '/tmp/SQL_LOAD-' (Errcode: 17), Error_code: 1

Setting tmpdir separately from each mysqld instance is certainly a workaround for this issue, but this should be a problem anyway.

How to repeat:
See above
[2 Aug 2011 11:09] Valeriy Kravchuk
Thank you for the problem report. Verified by code review.
[19 Dec 2011 1:29] Jon Stephens
Documented fix in the 5.6.5 changelog as follows:

      A race condition could occur when running multiple instances of mysqld on
      a single machine, when more than slave thread was started at the same
      time, and each such thread tried to use the same temporary file.

Closed.
[19 Dec 2011 1:29] Jon Stephens
Thank you for your bug report. This issue has been committed to our source repository of that product and will be incorporated into the next release.

If necessary, you can access the source repository and build the latest available version, including the bug fix. More information about accessing the source trees is available at

    http://dev.mysql.com/doc/en/installing-source.html