Skip to content
Snippets Groups Projects
Commit 74d3109e authored by Georgy Moshkin's avatar Georgy Moshkin :speech_balloon:
Browse files

fix(tarantool-sys): yielding on_shutdown triggers on ctrl-d

parent 2b30f83a
No related branches found
No related tags found
1 merge request!151Refactor/more minor changes
From 2242618aceaf955b5ded6d3cda857287e71a7a17 Mon Sep 17 00:00:00 2001
From: Georgy Moshkin <gmoshkin@picodata.io>
Date: Thu, 16 Jun 2022 17:13:58 +0300
Subject: [PATCH] fix(triggers): fix yielding on_shutdown triggers on ctrl-d
The problem was: when on_shutdown triggers are running at the end of the
main function, no event loop is running. So if a trigger yields, then
on_shutdown_fiber yields when trying to join it and returns execution
into the main fiber, which won't ever let the triggers run again.
A fix is to run the event loop in the main fiber while the on_shutdown
triggers are running. This event loop will be interrupted once the
triggers are finished and tarantool will be able to finish successfully.
---
src/main.cc | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/src/main.cc b/src/main.cc
index de082c17f..67ae056f1 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -100,6 +100,11 @@ static double start_time;
static struct fiber *on_shutdown_fiber = NULL;
/** A flag restricting repeated execution of tarantool_exit(). */
static bool is_shutting_down = false;
+/**
+ * A flag preventing main fiber from exiting until on_shutdown triggers have
+ * finished.
+ */
+static bool on_shutdown_is_running = false;
static int exit_code = 0;
double
@@ -136,9 +141,11 @@ static int
on_shutdown_f(va_list ap)
{
(void) ap;
+ on_shutdown_is_running = true;
trigger_fiber_run(&box_on_shutdown_trigger_list, NULL,
on_shutdown_trigger_timeout);
ev_break(loop(), EVBREAK_ALL);
+ on_shutdown_is_running = false;
return 0;
}
@@ -791,6 +803,10 @@ main(int argc, char **argv)
* any signals.
*/
tarantool_exit(exit_code);
+ if (on_shutdown_is_running) {
+ /* on_shutdown_fiber will call ev_break(ALL) after it ends */
+ ev_run(loop(), 0);
+ }
/* freeing resources */
tarantool_free();
return exit_code;
--
2.25.1
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment