Skip to content

Commit 945ab99

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

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

src/ngx_stream_lua_timer.c

+2
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,8 @@ ngx_stream_lua_timer_handler(ngx_event_t *ev)
730730
failed:
731731

732732
/* co stack: func [args] */
733+
lua_pushvalue(tctx.co, 1);
734+
/* co stack: func [args] func */
733735
lua_getinfo(tctx.co, ">Sf", &ar);
734736

735737
source = ar.source;

t/106-timer.t

+44
Original file line numberDiff line numberDiff line change
@@ -1910,3 +1910,47 @@ qr/\[alert\] .*? lua failed to run timer with function defined at @.+\/test.lua:
19101910
[crit]
19111911
[error]
19121912
[warn]
1913+
1914+
1915+
1916+
=== TEST 33: log function location when failed to run a timer with arg (lua file)
1917+
--- user_files
1918+
>>> test.lua
1919+
local _M = {}
1920+
1921+
function _M.run()
1922+
ngx.sleep(0.01)
1923+
end
1924+
1925+
return _M
1926+
--- stream_config
1927+
lua_package_path '$TEST_NGINX_HTML_DIR/?.lua;./?.lua;;';
1928+
lua_max_running_timers 1;
1929+
--- stream_server_config
1930+
content_by_lua_block {
1931+
local test = require "test"
1932+
1933+
local ok, err = ngx.timer.at(0, test.run, "arg")
1934+
if not ok then
1935+
ngx.say("failed to set timer: ", err)
1936+
return
1937+
end
1938+
1939+
local ok, err = ngx.timer.at(0, test.run, "arg")
1940+
if not ok then
1941+
ngx.say("failed to set timer: ", err)
1942+
return
1943+
end
1944+
1945+
ngx.say("ok")
1946+
}
1947+
--- stream_response
1948+
ok
1949+
--- wait: 0.1
1950+
--- error_log eval
1951+
qr/\[alert\] .*? lua failed to run timer with function defined at @.+\/test.lua:3: stream lua: 1 lua_max_running_timers are not enough/
1952+
--- no_error_log
1953+
[emerg]
1954+
[crit]
1955+
[error]
1956+
[warn]

0 commit comments

Comments
 (0)