Tarantool development patches archive
 help / color / mirror / Atom feed
* [Tarantool-patches] [PATCH] cbus: fix inconsistency in endpoint creation
@ 2020-04-22 19:56 Cyrill Gorcunov
  2020-04-24  7:57 ` Kirill Yukhin
  0 siblings, 1 reply; 2+ messages in thread
From: Cyrill Gorcunov @ 2020-04-22 19:56 UTC (permalink / raw)
  To: tml

The notification of wait variable shall be done under
a bound mutex locked. Otherwise the results are not
guaranteed (see pthread manuals).

Thus when we create a new endpoint via cbus_endpoint_create
and there is an other thread which sleeps inside cpipe_create
we should notify the sleeper under cbus.mutex.

Fixes #4806

Reported-by: Alexander Turenko <alexander.turenko@tarantool.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
---
issue https://github.com/tarantool/tarantool/issues/4806
branch gorcunov/gh-4806-cpipe-mutex

The fix is done on top of 1.10 series but 2.x series should be fixed as well.

 src/cbus.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/cbus.c b/src/cbus.c
index 314d7dc42..28164f666 100644
--- a/src/cbus.c
+++ b/src/cbus.c
@@ -234,7 +234,6 @@ cbus_endpoint_create(struct cbus_endpoint *endpoint, const char *name,
 	ev_async_start(endpoint->consumer, &endpoint->async);
 
 	rlist_add_tail(&cbus.endpoints, &endpoint->in_cbus);
-	tt_pthread_mutex_unlock(&cbus.mutex);
 	/*
 	 * Alert all waiting producers.
 	 *
@@ -243,6 +242,7 @@ cbus_endpoint_create(struct cbus_endpoint *endpoint, const char *name,
 	 * blocked on cond.
 	 */
 	tt_pthread_cond_broadcast(&cbus.cond);
+	tt_pthread_mutex_unlock(&cbus.mutex);
 	return 0;
 }
 
-- 
2.20.1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-04-24  7:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-22 19:56 [Tarantool-patches] [PATCH] cbus: fix inconsistency in endpoint creation Cyrill Gorcunov
2020-04-24  7:57 ` Kirill Yukhin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox