← Back to team overview

maria-developers team mailing list archive

Re: Problem with debug_sync, THD::enter_cond(), and kill ...


Hi, Kristian!

On Feb 26, Kristian Nielsen wrote:
> I got a crash in my parallel replication test case, and this one turned out to
> be caused by a fundamental  problem in debug_sync. I am not sure how to solve
> it, so I wanted to explain the issue in case others have some ideas.
> The crash happens in THD::awake() when a thread is killed:
>     mysql_mutex_lock(&mysys_var->mutex);
>     ...
>         int ret= mysql_mutex_trylock(mysys_var->current_mutex);
>         mysql_cond_broadcast(mysys_var->current_cond);
>         if (!ret)
>           mysql_mutex_unlock(mysys_var->current_mutex);
> The problem is that mysys_var->current_mutex changed between the trylock() and
> the unlock(), so we unlock a different mutex than the one we locked - ouch!

What about saving mysys_var->current_mutex locally before trylock-ing
it? Then you can be sure that you unlock what you've locked.

Races are still possible, you can signal a condition that doesn't
correspond to the mutex - but it doesn't really matter here.