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 #16776528 RACE CONDITION CAN CAUSE MYSQLD TO REMOVE SOCKET FILE ERRANTLY
Problem Description:
A mysqld_safe instance is started. An InnoDB crash recovery begins which takes
few seconds to complete. During this crash recovery process happening, another
mysqld_safe instance is started with the same server startup parameters. Since
the mysqld's pid file is absent during the crash recovery process the second
instance assumes there is no other process and tries to acquire a lock on the
ibdata files in the datadir. But this step fails and the 2nd instance keeps
retrying 100 times each with a delay of 1 second. Now after the 100 attempts,
the server goes down, but while going down it hits the mysqld_safe script's
cleanup section and without any check it blindly deletes the socket and pid
files. Since no lock is placed on the socket file, it gets deleted.
Solution:
We create a mysqld_safe.pid file in the datadir, which protects the presence
server instance resources by storing the mysqld_safe's process id in it. We
place a check if the mysqld_safe.pid file is existing in the datadir. If yes
then we check if the pid it contains is an active pid or not. If yes again,
then the scripts logs an error saying "A mysqld_safe instance is already
running". Otherwise it will log the present mysqld_safe's pid into the
mysqld_safe.pid file.
log_error "--syslog requested, but no 'logger' program found. Please ensure that 'logger' is in your PATH, or do not specify the --syslog option to mysqld_safe."
556
+
rm -f "$safe_pid"# Clean Up of mysqld_safe.pid file.
531
557
exit 1
532
558
fi
533
559
fi
@@ -542,6 +568,7 @@ then
542
568
543
569
# mysqld does not add ".err" to "--log-error=foo."; it considers a
544
570
# trailing "." as an extension
571
+
545
572
if expr "$err_log":'.*\.[^/]*$'> /dev/null
546
573
then
547
574
:
@@ -632,6 +659,7 @@ does not exist or is not executable. Please cd to the mysql installation
632
659
directory and restart this script from there as follows:
633
660
./bin/mysqld_safe&
634
661
See http://dev.mysql.com/doc/mysql/en/mysqld-safe.html for more information"
662
+
rm -f "$safe_pid"# Clean Up of mysqld_safe.pid file.
635
663
exit 1
636
664
fi
637
665
@@ -725,6 +753,7 @@ then
725
753
if @FIND_PROC@
726
754
then# The pid contains a mysqld process
727
755
log_error "A mysqld process already exists"
756
+
rm -f "$safe_pid"# Clean Up of mysqld_safe.pid file.
728
757
exit 1
729
758
fi
730
759
fi
@@ -735,6 +764,7 @@ then
735
764
$pid_file
736
765
Please remove it manually and start $0 again;
737
766
mysqld daemon not started"
767
+
rm -f "$safe_pid"# Clean Up of mysqld_safe.pid file.
738
768
exit 1
739
769
fi
740
770
fi
@@ -866,3 +896,5 @@ rm -f "$pid_file.shutdown"
866
896
867
897
log_notice "mysqld from pid file $pid_file ended"
868
898
899
+
rm -f "$safe_pid"# Some Extra Safety. File is deleted
0 commit comments