From 27fb397041c340eb757bd52086271e17bc99f83f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Tue, 18 Jun 2019 11:23:14 +0300 Subject: [PATCH] MXS-2547: Do shutdown on main worker By stopping the REST API before the workers and moving the shutdown to the same worker that handles REST API requests, we prevent the hang on shutdown. This also makes the signal handler signal-safe. --- server/core/admin.cc | 1 + server/core/gateway.cc | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/server/core/admin.cc b/server/core/admin.cc index 266226b5c..58396473a 100644 --- a/server/core/admin.cc +++ b/server/core/admin.cc @@ -410,6 +410,7 @@ bool mxs_admin_init() void mxs_admin_shutdown() { MHD_stop_daemon(http_daemon); + MXS_NOTICE("Stopped MaxScale REST API"); } bool mxs_admin_https_enabled() diff --git a/server/core/gateway.cc b/server/core/gateway.cc index 91da2c46d..aaf22e581 100644 --- a/server/core/gateway.cc +++ b/server/core/gateway.cc @@ -2293,9 +2293,6 @@ int main(int argc, char **argv) /*< Stop all the monitors */ monitorStopAll(); - /** Stop administrative interface */ - mxs_admin_shutdown(); - /*< Stop all the monitors */ monitorStopAll(); @@ -2380,6 +2377,19 @@ return_main: return rc; } /*< End of main */ +class ShutdownTask: public Worker::DisposableTask +{ +public: + void execute(mxs::Worker& w) + { + mxs_admin_shutdown(); + service_shutdown(); + Worker::shutdown_all(); + hkshutdown(); + log_flush_shutdown(); + } +}; + /*< * Shutdown MaxScale server */ @@ -2391,10 +2401,8 @@ int maxscale_shutdown() if (n == 0) { - service_shutdown(); - Worker::shutdown_all(); - hkshutdown(); - log_flush_shutdown(); + mxs::Worker* worker = Worker::get(0); + worker->post(std::auto_ptr(new ShutdownTask), mxs::Worker::EXECUTE_QUEUED); } return n + 1;