openresty 报错:lua entry thread aborted: runtime error

【1】问题现象nginx

(1)本地openresty系统app

(2)报错信息函数

2019/09/10 08:13:55 [error] 2385#2385: *4 lua entry thread aborted: runtime error: /usr/local/lib/ubcservd/bin/../work/bill_timer.lua:1647: attempt to concatenate global 'value' (a nil value)lua

(3)分析缘由spa

value变量为nil值的场景预先没有考虑到,致使链接字符串时失败。设计

(4)解决(容错)方案指针

打印value值时,增长nil值的判断。以下:rest

ngx.log(ngx.ERR, 'todo and print value: ' .. (value or 'nil'))

【2】问题追思日志

如上异常,出现过"lua entry thread aborted"之后,这个worker process(即id为2385)到底还存活吗?code

注意,这里所谓的存活是相对于C++程序的空指针致使应用程序异常崩溃而言。

模拟场景,分析过程以下:

(1)具体思路:

设计两个定时器,分别设置不一样的时间间隔(第一个时间间隔120s短于第二个180s),启动nginx系统:

当第一个定时器执行异常(如上错误)后,观察第二个定时器是否能够正常执行。

(2)源码以下:

[1] 配置文件:

nginx.conf,以下:

worker_processes  3;
user  root;

events 
{
    worker_connections  10000;
}

http 
{

    default_type  application/octet-stream;

    sendfile        on;

    send_timeout 60;
    keepalive_timeout  30;
    
    lua_package_path  "/usr/local/lib/ubcservd/lualib/?.lua;;";

    lua_package_cpath  "/usr/local/lib/ubcservd/lualib/?.so;;";
    
    init_worker_by_lua_file work/bill_timer.lua;

}

[2] 定时器文件:

bill_timer.lua,以下:

    local new_timer = ngx.timer.at

    local function timer_test_one(permature)
        if not premature then
            ngx.log(ngx.ERR, "into timer_test_one print value " .. value)

            local ok, err = new_timer(120, timer_test)
            if not ok then
                ngx.log(ngx.ERR, "failed to create timer_test_one timer : ", err)
            else
                ngx.log(ngx.ERR, "success to create timer_test_one timer interval(s) : " .. '120')
            end
        end
    end

    local function timer_test_two(permature)
        if not premature then
            ngx.log(ngx.ERR, "into timer_test_two print ")

            local ok, err = new_timer(180, timer_test_two)
            if not ok then
                ngx.log(ngx.ERR, "failed to create timer_test_two timer : ", err)
            else
                ngx.log(ngx.ERR, "success to create timer_test_two timer interval(s) : " .. '180')
            end
        end
    end

    if 0 == ngx.worker.id() then
        local ok, err = new_timer(120, timer_test_one)
        if not ok then
            ngx.log(ngx.ERR, "failed to create timer_test_one timer : " .. err)
        else
            ngx.log(ngx.ERR, "success to create timer_test_one timer interval(s) : " .. '120')
        end

        local ok, err = new_timer(180, timer_test_two)
        if not ok then
            ngx.log(ngx.ERR, "failed to create timer_test_two timer : " .. err)
        else
            ngx.log(ngx.ERR, "success to create timer_test_two timer interval(s) : " .. '180')
        end
    end

[3] 启动nginx系统

成功启动,建立3个worker process,以下图:

[4] 日志分析

第一个定时器执行异常停止错误信息,当即观察worker进程状况:

进程id值为2869仍然存在,安然无恙。

第二个定时器执行正常打印信息,全部日志,以下图:

综上所述:“thread aborted” 并不是崩溃,仅仅只是当前函数执行失败停止,此函数其他语句不会再执行。

 

Good Good Study, Day Day Up.

顺序 选择 循环 总结

相关文章
相关标签/搜索