feature: allow creating 0-delay timers upon worker process existing.
This commit is contained in:
Родитель
e5f63816bf
Коммит
4d6dc5804a
|
@ -86,7 +86,7 @@ ngx_http_lua_ngx_timer_at(lua_State *L)
|
|||
return luaL_error(L, "no request");
|
||||
}
|
||||
|
||||
if (ngx_exiting) {
|
||||
if (ngx_exiting && delay > 0) {
|
||||
lua_pushnil(L);
|
||||
lua_pushliteral(L, "process exiting");
|
||||
return 2;
|
||||
|
@ -210,7 +210,7 @@ ngx_http_lua_ngx_timer_at(lua_State *L)
|
|||
|
||||
tctx = (ngx_http_lua_timer_ctx_t *) p;
|
||||
|
||||
tctx->premature = 0;
|
||||
tctx->premature = ngx_exiting ? 1 : 0;
|
||||
tctx->co_ref = co_ref;
|
||||
tctx->co = co;
|
||||
tctx->main_conf = r->main_conf;
|
||||
|
@ -636,11 +636,13 @@ ngx_http_lua_abort_pending_timers(ngx_event_t *ev)
|
|||
ev->handler(ev);
|
||||
}
|
||||
|
||||
if (lmcf->pending_timers) {
|
||||
#if 0
|
||||
if (pending_timers) {
|
||||
ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0,
|
||||
"lua pending timer counter got out of sync: %i",
|
||||
lmcf->pending_timers);
|
||||
pending_timers);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* vi:set ft=c ts=4 sw=4 et fdm=marker: */
|
||||
|
|
|
@ -28,7 +28,7 @@ our $StapScript = $t::StapThread::StapScript;
|
|||
|
||||
repeat_each(2);
|
||||
|
||||
plan tests => repeat_each() * 45;
|
||||
plan tests => repeat_each() * 59;
|
||||
|
||||
#no_diff();
|
||||
no_long_string();
|
||||
|
@ -177,7 +177,7 @@ timer prematurely expired: true
|
|||
|
||||
local function f(premature)
|
||||
print("timer prematurely expired: ", premature)
|
||||
local ok, err = ngx.timer.at(0, f)
|
||||
local ok, err = ngx.timer.at(3, f)
|
||||
if not ok then
|
||||
print("failed to register a new timer after reload: ", err)
|
||||
else
|
||||
|
@ -214,3 +214,65 @@ http lua close fake http connection
|
|||
timer prematurely expired: true
|
||||
failed to register a new timer after reload: process exiting, context: ngx.timer
|
||||
|
||||
|
||||
|
||||
=== TEST 4: trying to add new timer after HUP reload
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua '
|
||||
local f, err = io.open("t/servroot/logs/nginx.pid", "r")
|
||||
if not f then
|
||||
ngx.say("failed to open nginx.pid: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
local pid = f:read()
|
||||
-- ngx.say("master pid: [", pid, "]")
|
||||
|
||||
f:close()
|
||||
|
||||
local function g(premature)
|
||||
print("g: timer prematurely expired: ", premature)
|
||||
end
|
||||
|
||||
local function f(premature)
|
||||
print("f: timer prematurely expired: ", premature)
|
||||
local ok, err = ngx.timer.at(0, g)
|
||||
if not ok then
|
||||
print("f: failed to register a new timer after reload: ", err)
|
||||
else
|
||||
print("f: registered a new timer after reload")
|
||||
end
|
||||
end
|
||||
local ok, err = ngx.timer.at(3, f)
|
||||
if not ok then
|
||||
ngx.say("failed to set timer: ", err)
|
||||
return
|
||||
end
|
||||
ngx.say("registered timer")
|
||||
os.execute("kill -HUP " .. pid)
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
|
||||
--- response_body
|
||||
registered timer
|
||||
|
||||
--- wait: 0.2
|
||||
--- no_error_log
|
||||
[error]
|
||||
[alert]
|
||||
[crit]
|
||||
in callback: hello, 2
|
||||
timer prematurely expired: false
|
||||
failed to register a new timer after reload
|
||||
|
||||
--- error_log
|
||||
lua abort pending timers
|
||||
lua ngx.timer expired
|
||||
http lua close fake http connection
|
||||
f: timer prematurely expired: true
|
||||
f: registered a new timer after reload
|
||||
g: timer prematurely expired: true
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче