List:Internals« Previous MessageNext Message »
From:Michael Widenius Date:October 20 2002 6:00pm
Subject:[PATCH] mysys/my_symlink.c -- realpath() not thread-safe on FreeBSD.
View as plain text  

>>>>> "Jeremy" == Jeremy Zawodny <Jeremy@stripped> writes:

Jeremy> Hi Monty & others,

Jeremy> We've *finally* tracked down a mysterious MySQL problem that has been
Jeremy> affecting some of our FreeBSD/MySQL/LinuxThreads servers.  It turns
Jeremy> out that FreeBSD's realpath() isn't thread-safe.  The result is that
Jeremy> you can have two processes both changing the current working directory
Jeremy> (realpath() does a a chdir() behind the scenes) on a shared file
Jeremy> descriptor and tries to restore it later and leaving the file
Jeremy> descriptor in an improper state.  It's a simple race condition.

This is the same thing as we have seen on BSD and Mac OS X.

Jeremy> This doesn't *seem* to affect MySQL using FreeBSD's native threads,
Jeremy> because they are not pre-emptive or SMP aware.  In order to use SMP,
Jeremy> we often build MySQL with LinuxThreads.  The performance is excellent
Jeremy> this way.

It's actually a bit worse than that.

MySQL opens all files relative to the current directory.  If one
thread opens a file while another thread is doing realpath() then
the open may fail.

Jeremy> The attached patch (below my sig) is *our* fix.  A proper patch should
Jeremy> only implement the mutex on FreeBSD and probably omit the warning that
Jeremy> we added.  Given how infrequently my_realpath() is called, it's
Jeremy> probably not worth making it specific to FreeBSD/LinuxThreads--but
Jeremy> that's obviously your decision.

Jeremy> Could something appropriate be applied to at least the 4.0 and 4.1
Jeremy> trees?  I'm running this patch in production on MySQL 4.0.5.


A better option than protecting realpath with a mutex is to compile

In effect this means that one MySQL will forgot symlinks to a table if
you do a REPAIR or ALTER TABLE and you can't symlink two databases to
the same database directory.

Jeremy, is the above restrictions a problem for you ?

Lenz, can you please add the above the freebds options and add a note
about this to the manual for all OS we compile with


For technical support contracts, goto
   __  ___     ___ ____  __
  /  |/  /_ __/ __/ __ \/ /    Mr. Michael Widenius <monty@stripped>
 / /|_/ / // /\ \/ /_/ / /__   MySQL AB, CTO
/_/  /_/\_, /___/\___\_\___/   Helsinki, Finland
[PATCH] mysys/my_symlink.c -- realpath() not thread-safe on FreeBSD.Jeremy Zawodny18 Oct
  • [PATCH] mysys/my_symlink.c -- realpath() not thread-safe on FreeBSD.Michael Widenius20 Oct
    • Re: [PATCH] mysys/my_symlink.c -- realpath() not thread-safe on FreeBSD.Jeremy Zawodny20 Oct