[tor-commits] [tor/master] New testcase exposing bug during threadpool shutdown
nickm at torproject.org
nickm at torproject.org
Fri Aug 21 14:37:17 UTC 2015
commit 2657ea802bd9633aeea8774b32d64ed671624818
Author: Sebastian Hahn <sebastian at torproject.org>
Date: Thu Aug 20 19:57:08 2015 +0200
New testcase exposing bug during threadpool shutdown
We don't want to accept any work after one of our worker functions has
returned WQ_RPL_SHUTDOWN. This testcase currently fails, because we do
not actually stop any of the worker threads.
---
src/test/test_workqueue.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/src/test/test_workqueue.c b/src/test/test_workqueue.c
index 7f20642..1d2cd94 100644
--- a/src/test/test_workqueue.c
+++ b/src/test/test_workqueue.c
@@ -124,6 +124,14 @@ workqueue_do_ecdh(void *state, void *work)
return WQ_RPL_REPLY;
}
+static int
+workqueue_shutdown_error(void *state, void *work)
+{
+ (void)state;
+ (void)work;
+ return WQ_RPL_REPLY;
+}
+
static void *
new_state(void *arg)
{
@@ -156,6 +164,7 @@ static int n_sent = 0;
static int rsa_sent = 0;
static int ecdh_sent = 0;
static int n_received = 0;
+static int no_shutdown = 0;
#ifdef TRACK_RESPONSES
bitarray_t *received;
@@ -174,6 +183,14 @@ handle_reply(void *arg)
++n_received;
}
+/* This should never get called. */
+static void
+handle_reply_shutdown(void *arg)
+{
+ (void)arg;
+ no_shutdown = 1;
+}
+
static workqueue_entry_t *
add_work(threadpool_t *tp)
{
@@ -288,6 +305,8 @@ replysock_readable_cb(tor_socket_t sock, short what, void *arg)
shutting_down = 1;
threadpool_queue_update(tp, NULL,
workqueue_do_shutdown, NULL, NULL);
+ // Anything we add after starting the shutdown must not be executed.
+ threadpool_queue_work(tp, workqueue_shutdown_error, handle_reply_shutdown, NULL);
{
struct timeval limit = { 2, 0 };
tor_event_base_loopexit(tor_libevent_get_base(), &limit);
@@ -416,6 +435,9 @@ main(int argc, char **argv)
printf("%d+%d vs %d\n", n_received, n_successful_cancel, n_sent);
puts("FAIL");
return 1;
+ } else if (no_shutdown) {
+ puts("Accepted work after shutdown\n");
+ puts("FAIL");
} else {
puts("OK");
return 0;
More information about the tor-commits
mailing list