Fixed mysql race condition