Tarantool development patches archive
 help / color / mirror / Atom feed
* [PATCH] replication: fix assertion in relay_cancel()
@ 2018-08-17 13:59 Serge Petrenko
  2018-08-17 15:06 ` Vladimir Davydov
  0 siblings, 1 reply; 2+ messages in thread
From: Serge Petrenko @ 2018-08-17 13:59 UTC (permalink / raw)
  To: vdavydov.dev; +Cc: georgy, kostja, tarantool-patches, Serge Petrenko

If relay thread is already exiting (but hadn't executed relay_stop()
yet) and relay_cancel() is called we may encounter an error trying to
call pthread_cancel() after the thread has exited. Handle this case.

Follow-up #3485
---
https://github.com/tarantool/tarantool/issues/3485
https://github.com/tarantool/tarantool/tree/sp/relay-cancel-fix

 src/box/relay.cc | 3 ++-
 src/tt_pthread.h | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/box/relay.cc b/src/box/relay.cc
index b9919ea86..138e66dd5 100644
--- a/src/box/relay.cc
+++ b/src/box/relay.cc
@@ -203,7 +203,8 @@ relay_cancel(struct relay *relay)
 {
 	/* Check that the thread is running first. */
 	if (relay->cord.id != 0) {
-		tt_pthread_cancel(relay->cord.id);
+		if (tt_pthread_cancel(relay->cord.id) == ESRCH)
+			return;
 		tt_pthread_join(relay->cord.id, NULL);
 	}
 }
diff --git a/src/tt_pthread.h b/src/tt_pthread.h
index d83694460..40b43b112 100644
--- a/src/tt_pthread.h
+++ b/src/tt_pthread.h
@@ -279,7 +279,8 @@
 
 #define tt_pthread_cancel(thread)			\
 ({	int e__ = pthread_cancel(thread);		\
-	tt_pthread_error(e__);				\
+	assert(e__ == 0 || e__ == ESRCH);		\
+	e__;						\
 })
 
 #define tt_pthread_key_create(key, dtor)		\
-- 
2.15.2 (Apple Git-101.1)

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

* Re: [PATCH] replication: fix assertion in relay_cancel()
  2018-08-17 13:59 [PATCH] replication: fix assertion in relay_cancel() Serge Petrenko
@ 2018-08-17 15:06 ` Vladimir Davydov
  0 siblings, 0 replies; 2+ messages in thread
From: Vladimir Davydov @ 2018-08-17 15:06 UTC (permalink / raw)
  To: Serge Petrenko; +Cc: georgy, kostja, tarantool-patches

Pushed to 1.10

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

end of thread, other threads:[~2018-08-17 15:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-17 13:59 [PATCH] replication: fix assertion in relay_cancel() Serge Petrenko
2018-08-17 15:06 ` Vladimir Davydov

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