Skip to content

Commit 98f482b

Browse files
bugfix: process may crash when a timer run failed and a function with arguments run inside this timer. (#1819)
used the uninitialized "ar" value due to the unexpected Lua stack and lua_getinfo will be failed to set the "ar" value.
1 parent e497ffc commit 98f482b

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

src/ngx_http_lua_timer.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,8 @@ ngx_http_lua_timer_handler(ngx_event_t *ev)
670670
failed:
671671

672672
/* co stack: func [args] */
673+
lua_pushvalue(tctx.co, 1);
674+
/* co stack: func [args] func */
673675
lua_getinfo(tctx.co, ">Sf", &ar);
674676

675677
source = ar.source;

t/106-timer.t

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2349,3 +2349,49 @@ ok
23492349
[error]
23502350
--- error_log eval
23512351
qr/\[alert\] .*? lua failed to run timer with function defined at @.+\/test.lua:3: 1 lua_max_running_timers are not enough/
2352+
2353+
2354+
2355+
=== TEST 36: log function location when failed to run a timer with args (lua file)
2356+
--- user_files
2357+
>>> test.lua
2358+
local _M = {}
2359+
2360+
function _M.run(premature, arg)
2361+
ngx.sleep(0.01)
2362+
end
2363+
2364+
return _M
2365+
--- http_config
2366+
lua_package_path '$TEST_NGINX_HTML_DIR/?.lua;./?.lua;;';
2367+
lua_max_running_timers 1;
2368+
--- config
2369+
location /t {
2370+
content_by_lua_block {
2371+
local test = require "test"
2372+
2373+
local ok, err = ngx.timer.at(0, test.run, "arg")
2374+
if not ok then
2375+
ngx.say("failed to set timer: ", err)
2376+
return
2377+
end
2378+
2379+
local ok, err = ngx.timer.at(0, test.run, "arg")
2380+
if not ok then
2381+
ngx.say("failed to set timer: ", err)
2382+
return
2383+
end
2384+
2385+
ngx.say("ok")
2386+
}
2387+
}
2388+
--- request
2389+
GET /t
2390+
--- response_body
2391+
ok
2392+
--- wait: 0.1
2393+
--- no_error_log
2394+
[crit]
2395+
[error]
2396+
--- error_log eval
2397+
qr/\[alert\] .*? lua failed to run timer with function defined at @.+\/test.lua:3: 1 lua_max_running_timers are not enough/

0 commit comments

Comments
 (0)