mysqld_safe and pid file creation race condition

mysql_safe is responsible for restarting mysqld if it crashes and will exit cleanly if mysqld was shutdown. The way it determines if mysqld shutdown correctly is if the pid file is cleaned up correctly. MySQL does quite a few things before creating the pid file like initializing storage engines. It can take quite a while to initialize innodb if it has to roll forward the transaction log. During this time if mysqld crashes mysqld_safe won’t restart it. Normally this is ok because the server would just crash again but it can mess with your head a bit if you’re testing changes to mysqld_safe. Especially if those changes involve what mysqld_safe does if mysqld crashes. I think it makes sense to create the pidfile earlier and there is a bug for it. Chime in on the bug if this has burned you.

3 Comments

  1. Mark Callaghan says:

    I have had some fun with mysqld_safe. Most from it not waiting long enough for mysqld to shutdown. By default shutdown waits for InnoDB to flush all dirty pages and with a large buffer pool that can take a long time. The result is that it times out before mysqld stops and that can will make ‘mysqld restart’ not restart mysqld.

  2. [...] I wrote about how late the mysql pid file is created in the startup process. At first glance it seemed like [...]

  3. [...] As long as we’re in /var, here’s Eric Bergen attempting to unwind the tangled web of pid file creation, which he started doing having discovered a pid file creation race condition in mysqld_safe. [...]

Leave a Reply