From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id B70432D41C for ; Mon, 26 Nov 2018 09:25:33 -0500 (EST) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id hHe1Kgzlvi4z for ; Mon, 26 Nov 2018 09:25:33 -0500 (EST) Received: from smtp44.i.mail.ru (smtp44.i.mail.ru [94.100.177.104]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 751142B1A4 for ; Mon, 26 Nov 2018 09:25:33 -0500 (EST) From: Serge Petrenko Subject: [tarantool-patches] [PATCH v2 1/3] box: implement on_shutdown triggers Date: Mon, 26 Nov 2018 17:25:04 +0300 Message-Id: <144b51c2071b2f5cad0030307733debc76b02641.1543241956.git.sergepetrenko@tarantool.org> In-Reply-To: References: In-Reply-To: References: Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: kostja@tarantool.org, tarantool-patches@freelists.org From: Konstantin Osipov @sergepetrenko: Factor out running on_shutdown triggers from box_free() into a separate function. In tarantool_free() run on_shutdown triggers before coio_shutdown(), but leave box_free() after coio_shutdown(). Otherwise tarantool hangs on shutdown occasionally. --- src/box/box.cc | 8 ++++++++ src/box/box.h | 11 +++++++++++ src/main.cc | 2 ++ 3 files changed, 21 insertions(+) diff --git a/src/box/box.cc b/src/box/box.cc index 7a1171c62..72049fabf 100644 --- a/src/box/box.cc +++ b/src/box/box.cc @@ -78,6 +78,8 @@ static char status[64] = "unknown"; /** box.stat rmean */ struct rmean *rmean_box; +struct rlist on_shutdown = RLIST_HEAD_INITIALIZER(on_shutdown); + static void title(const char *new_status) { snprintf(status, sizeof(status), "%s", new_status); @@ -1645,6 +1647,12 @@ box_set_replicaset_uuid(const struct tt_uuid *replicaset_uuid) diag_raise(); } +void +box_run_on_shutdown_triggers(void) +{ + trigger_run(&on_shutdown, NULL); +} + void box_free(void) { diff --git a/src/box/box.h b/src/box/box.h index 9f5b3acbd..e2c3aad9e 100644 --- a/src/box/box.h +++ b/src/box/box.h @@ -63,6 +63,11 @@ struct vclock; */ extern const struct vclock *box_vclock; +struct trigger; + +/** Invoked on box shutdown. */ +extern struct rlist on_shutdown; + /* * Initialize box library * @throws C++ exception @@ -76,6 +81,12 @@ box_init(void); void box_free(void); +/** + * Run on_shutdown triggers. + */ +void +box_run_on_shutdown_triggers(void); + /** * Load configuration for box library. * Panics on error. diff --git a/src/main.cc b/src/main.cc index a36a2b0d0..987c53834 100644 --- a/src/main.cc +++ b/src/main.cc @@ -544,6 +544,8 @@ tarantool_free(void) if (!cord_is_main()) return; + box_run_on_shutdown_triggers(); + /* Shutdown worker pool. Waits until threads terminate. */ coio_shutdown(); -- 2.17.2 (Apple Git-113)