# HG changeset patch # User jbe # Date 1497274113 -7200 # Node ID b355e259c81e813eef6fab2cb767ee21134fed53 # Parent 7c67bdf99cb52bbb16bb7bdc9825472dc7c0051f Do not reuse child workers that have been SIGTERM'ed diff -r 7c67bdf99cb5 -r b355e259c81e moonbridge.c --- a/moonbridge.c Mon Jun 12 13:57:38 2017 +0200 +++ b/moonbridge.c Mon Jun 12 15:28:33 2017 +0200 @@ -755,13 +755,13 @@ char controlmsg; int fd; struct itimerval notimer = { { 0, }, { 0, } }; - moonbr_io_catch_sigterm(L); // NOTE: should not fail lua_rawgetp(L, LUA_REGISTRYINDEX, moonbr_luakey_prepare_func(pool)); if (lua_isnil(L, -1)) lua_pop(L, 1); else if (lua_pcall(L, 0, 0, 1)) { fprintf(stderr, "Error in \"prepare\" function: %s\n", lua_tostring(L, -1)); exit(1); } + moonbr_io_catch_sigterm(L); // NOTE: should not fail while (1) { struct moonbr_listener *listener; if (setitimer(ITIMER_REAL, ¬imer, NULL)) { @@ -779,6 +779,7 @@ moonbr_child_log_fatal("Received illegal control message from parent process"); } if (controlmsg == MOONBR_COMMAND_TERMINATE) break; + moonbr_io_sigterm_flag = 0; /* ignore any prior SIGTERM (can't be handled in blocking recv anyway) */ listener = moonbr_child_receive_pointer(MOONBR_FD_CONTROL); if ( listener->proto != MOONBR_PROTO_LOCAL && @@ -814,7 +815,10 @@ exit(1); } if (fd >= 0) moonbr_io_closehandle(L, -2, 0); /* attemt clean close */ - if (lua_type(L, -1) != LUA_TBOOLEAN || !lua_toboolean(L, -1)) break; + if ( + moonbr_io_sigterm_flag || + lua_type(L, -1) != LUA_TBOOLEAN || !lua_toboolean(L, -1) + ) break; #ifdef MOONBR_LUA_PANIC_BUG_WORKAROUND lua_settop(L, 2); #else diff -r 7c67bdf99cb5 -r b355e259c81e moonbridge_io.c --- a/moonbridge_io.c Mon Jun 12 13:57:38 2017 +0200 +++ b/moonbridge_io.c Mon Jun 12 15:28:33 2017 +0200 @@ -116,7 +116,7 @@ pid_t pid; } moonbr_io_child_t; -static volatile sig_atomic_t moonbr_io_sigterm_flag = 0; +volatile sig_atomic_t moonbr_io_sigterm_flag = 0; static int moonbr_io_yield(lua_State *L) { return lua_yield(L, lua_gettop(L)); diff -r 7c67bdf99cb5 -r b355e259c81e moonbridge_io.h --- a/moonbridge_io.h Mon Jun 12 13:57:38 2017 +0200 +++ b/moonbridge_io.h Mon Jun 12 15:28:33 2017 +0200 @@ -1,4 +1,5 @@ +volatile sig_atomic_t moonbr_io_sigterm_flag; void moonbr_io_pushhandle(lua_State *L, int fd); void moonbr_io_closehandle(lua_State *L, int idx, int reset); int moonbr_io_catch_sigterm(lua_State *L);