Tarantool development patches archive
 help / color / mirror / Atom feed
* [Tarantool-patches] [PATCH] Add a cancellation guard to cpipe flush callback
@ 2019-12-03 16:33 Leonid Vasiliev
  2019-12-03 18:02 ` Konstantin Osipov
  0 siblings, 1 reply; 8+ messages in thread
From: Leonid Vasiliev @ 2019-12-03 16:33 UTC (permalink / raw)
  To: alexander.turenko; +Cc: tarantool-patches

https://github.com/tarantool/tarantool/issues/4127
https://github.com/tarantool/tarantool/tree/lvasiliev/gh-4127-WAL-thread-stucks

We need to set a thread cancellation guard, because
another thread may cancel the current thread
(write() is a cancellation point in ev_async_send)
and the activation of the ev_async watcher
through ev_async_send will fail.

---
 src/lib/core/cbus.c | 13 +++++++++++++
 src/tt_pthread.h    |  5 +++++
 2 files changed, 18 insertions(+)

diff --git a/src/lib/core/cbus.c b/src/lib/core/cbus.c
index b3b1280e7..7e9ef91e3 100644
--- a/src/lib/core/cbus.c
+++ b/src/lib/core/cbus.c
@@ -284,6 +284,17 @@ cpipe_flush_cb(ev_loop *loop, struct ev_async *watcher, int events)
 	/* Trigger task processing when the queue becomes non-empty. */
 	bool output_was_empty;
 
+	/*
+	 * We need to set a thread cancellation guard, because
+	 * another thread may cancel the current thread
+	 * (write() is a cancellation point in ev_async_send)
+	 * and the activation of the ev_async watcher
+	 * through ev_async_send will fail.
+	 */
+
+	int old_cancel_state;
+	tt_pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &old_cancel_state);
+
 	tt_pthread_mutex_lock(&endpoint->mutex);
 	output_was_empty = stailq_empty(&endpoint->output);
 	/** Flush input */
@@ -297,6 +308,8 @@ cpipe_flush_cb(ev_loop *loop, struct ev_async *watcher, int events)
 
 		ev_async_send(endpoint->consumer, &endpoint->async);
 	}
+
+	tt_pthread_setcancelstate(old_cancel_state, NULL);
 }
 
 void
diff --git a/src/tt_pthread.h b/src/tt_pthread.h
index 40b43b112..6bb19eb23 100644
--- a/src/tt_pthread.h
+++ b/src/tt_pthread.h
@@ -300,6 +300,11 @@
 
 #define tt_pthread_getspecific(key) pthread_getspecific(key)
 
+#define tt_pthread_setcancelstate(state, oldstate)	\
+({	int e__ = pthread_setcancelstate(state, oldstate);\
+	tt_pthread_error(e__);				\
+})
+
 /** Set the current thread's name
  */
 static inline void
-- 
2.17.1

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

end of thread, other threads:[~2019-12-24 15:33 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-03 16:33 [Tarantool-patches] [PATCH] Add a cancellation guard to cpipe flush callback Leonid Vasiliev
2019-12-03 18:02 ` Konstantin Osipov
2019-12-05  7:22   ` Leonid Vasiliev
2019-12-05  7:27     ` Konstantin Osipov
2019-12-23 12:44       ` Leonid Vasiliev
2019-12-23 12:55         ` Konstantin Osipov
2019-12-24 15:27           ` Leonid Vasiliev
2019-12-24 15:33             ` Konstantin Osipov

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