[PATCH] Fix a pthreadpool race

Christof Schmitt cs at samba.org
Tue Dec 12 22:20:35 UTC 2017


On Tue, Dec 12, 2017 at 11:17:26PM +0100, Volker Lendecke wrote:
> On Tue, Dec 12, 2017 at 11:10:55PM +0100, Volker Lendecke wrote:
> > On Tue, Dec 12, 2017 at 01:02:46PM -0700, Christof Schmitt wrote:
> > > The assumption here is that no call to pthread_create is done and hence no call
> > > to will_return is required. What likely happened is that the worker thread
> > > exited, then test_create_do triggered the creation of a new pthread, which in
> > > turn caused a call to mock_type. As there is no entry in the global list,
> > > cmocka tried to abort through a jump while still holding the mutex.
> > 
> > The helper thread did not exit, it was *not yet* idle.
> > 
> > The attached patch fixes the problem for me.
> 
> Gna. Forgot to add the mailing list reference. Same patch, new commit
> msg.

Reviewed and pushed updated patch.

Christof

> 
> Volker
> 
> -- 
> SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
> phone: +49-551-370000-0, fax: +49-551-370000-9
> AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
> http://www.sernet.de, mailto:kontakt at sernet.de

> From 83f01a22522f0efd7e6138577b8c427e2223b02f Mon Sep 17 00:00:00 2001
> From: Volker Lendecke <vl at samba.org>
> Date: Tue, 12 Dec 2017 23:07:39 +0100
> Subject: [PATCH] pthreadpool: Fix deadlock
> 
> Christof's idea from
> 
> https://lists.samba.org/archive/samba-technical/2017-December/124384.html
> 
> was that the thread already exited. It could also be that the thread is
> not yet idle when the new pthreadpool_add_jobs comes around the corner.
> 
> Signed-off-by: Volker Lendecke <vl at samba.org>
> ---
>  lib/pthreadpool/tests_cmocka.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/lib/pthreadpool/tests_cmocka.c b/lib/pthreadpool/tests_cmocka.c
> index 75a935fa42c..9753d212e1c 100644
> --- a/lib/pthreadpool/tests_cmocka.c
> +++ b/lib/pthreadpool/tests_cmocka.c
> @@ -28,6 +28,7 @@
>  #include <pthreadpool_tevent.h>
>  
>  #include <cmocka.h>
> +#include <poll.h>
>  
>  struct pthreadpool_tevent_test {
>  	struct tevent_context *ev;
> @@ -152,6 +153,8 @@ static void test_create(void **state)
>  	assert_return_code(ret, 0);
>  	assert_false(in_main_thread);
>  
> +	poll(NULL, 0, 10);
> +
>  	/*
>  	 * Workerthread will still be active for a second; immediately
>  	 * running another job will also use the worker thread, even
> -- 
> 2.11.0
> 




More information about the samba-technical mailing list