openresty 报错:lua entry thread aborted: runtime error

【1】问题现象

(1)本地openresty系统

(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)

(3)分析原因

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

(4)解决(容错)方案

打印value值时,增加nil值的判断。如下:

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

【2】问题追思

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

注意,这里所谓的存活是相对于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.

顺序 选择 循环 总结

转载于:https://www.cnblogs.com/Braveliu/p/11503160.html

Nginx+lua 调用.so文件 最近在和智能硬件部门一起,做一个室内定位的服务,该服务根据手机端传过来的beacon设备列表,根据一定的算法计算出具体的商场,并将商场ID和beason设备列表作为参数,调用.so文件中的计算方法,得出位置数据(坐标:x、y、z),返回给手机端。因为服务对QPS要求比较高,并且都是纯查询操作,于是决定使用Nginx+lua+Redis的架构(该架构在公司内部已成主流,比较成熟)。下面我将对lua调用 阅读详情

相关推荐

lua entry thread aborted: runtime error: /usr/../process.lua:448: attempt to concatenate field 'np_s...

【1】问题场景原代码 引起问题的原代码,访问数据库,汇总数据后,使用汇总结果报异常: 1 local function amount_sum_fee(cycleid) 2 local select_productid = "select product_id from np_cdr_" .. cycleid .. " group by product_id;"...

weixin_30920513的博客 1523

OpenResty+lua查询数据库数据失败

lua entry thread aborted: runtime error: /usr/local/openresty/lualib/resty/mysql.lua:236: attempt to perform arithmetic on field ‘packet_no’ (a nil value) 在使用OpenResty 利用lua查询mysql数据时遇到了查不到数据的情况 折腾了很久看来很多博客还是没有解决 突然想到可以去看看日志于是在/usr/local/openresty/nginx/.

weixin_45996580的博客 3147

lua entry thread aborted: runtime error: attempt to yield across C-call boundary stack traceback

一个lua脚本里引入其它脚本文件一直报错lua entry thread aborted: runtime error: attempt to yield across C-call boundary stack traceback: coroutine 0: [C]: in function 'require' 错误位置定位到require另外一个lua脚本的位置。很认真的...

xiejunna的博客 6365

openResty的Redis模块踩坑记录

OpenResty提供了操作Redis的模块,我们只要引入该模块就能直接使用。说是这样说,但是实践起来好像并不太顺利。

帅得山崩地裂的专栏 1935

【大数据开发】lua entry thread aborted: runtime error: /usr/local/openresty/lualib/controller.lua:37: attem

2020/10/27 21:21:03 [error] 12539#12539: *71 lua entry thread aborted: runtime error: /usr/local/openresty/lualib/controller.lua:37: attempt to index local 'shared_data' (a nil value) stack traceback: coroutine 0: /usr/local/openresty/lualib/contro

白色风车 2408

Nginx/OpenResty+Lua实战

OpenResty集成了Nginx,在支持Nginx所有的功能前提下,整合了Lua、Mysql、 Redis、Memcached等插件,使Nginx功能更强大。做7层负载均衡,做web开发,缓存,流控、waf、网关 LUA第三方库存放在openresty\lualib\resty目录下,即可在lua中调用 功能分P解说 https://space.bilibili.com/431715942...

shanchahua123456的博客 2191

Godot 4集成Lua实战:从原理到性能优化的完整指南

在游戏开发中,脚本语言是连接游戏逻辑与引擎核心的桥梁,其选择直接影响开发效率和项目架构。Lua以其轻量、高效和卓越的热更新能力,成为许多游戏项目,尤其是移动端和需要快速迭代场景的首选。其原理在于通过可嵌入的C库,为宿主程序提供灵活的运行时脚本环境,实现逻辑与引擎的解耦。这项技术的核心价值在于提升开发灵活性、支持动态代码更新,并能复用庞大的现有Lua生态代码库。应用场景广泛,从UI逻辑、技能配置到服务器共享逻辑均可覆盖。本文将聚焦于如何将Lua深度集成至Godot 4引擎,通过C++原生扩展(GDExtens

dieqiao8331的博客 299

开发中遇到的某些 bug

【代码】开发中遇到的某些 bug。

qq_35417353的博客 372

nginx lua 调试 - 死磕

疯狂创客圈 Java 高并发【 亿级流量聊天室实战】实战系列 【博客园总入口 】 架构师成长+面试必备之 高并发基础书籍 【Netty Zookeeper Redis 高并发实战 】 前言 Crazy-SpringCloud 微服务脚手架 &视频介绍: Crazy-SpringCloud 微服务脚手架,是为 Java 微服务开发 入门者 准备的 学习和开发脚手架。并配有一系列的使用教程...

架构师尼恩 2700

编译lua-cjson成功但使用时找不到cjson的问题解决

error loading module 'cjson' from file '.\cjson.dll': 找不到指定的程序

u012042615的专栏 1801

Lua编程时遇到的一个错误:attempt to index upvalue

最近用OpenResty开发一个产品。新学Lua语言,写了不少脚本。前几天遇到这么一个运行时错误: 2022/01/21 18:57:01 [error] 581744#0: *74 lua entry thread aborted: runtime error: /opt/lua/blacklist.lua:98: attempt to index upvalue 'actions' (a number value) 简化一下,blacklist.lua代码如下: local actions =

wesleyflagon的专栏 5120

nginx+lua+redis deny ip

2019独角兽企业重金招聘Python工程师标准>>> ...

weixin_33910137的博客 335

error loading module ‘cjson‘ from file ‘.\cjson.dll‘:找不到指定的程序。

lua-cjson error loading module 'cjson' from file '.\cjson.dll':找不到指定的程序。

Miss_Mario的专栏 1180

lua 使用中遇到的坑总结

前言 竹子是 java程序员一枚,最近在做一个登录的改造,用lua实现,现在基本算是告一段落,然后在此分享下在过程中遇到的坑吧。 一定要注意使用 lua的版本,版本不同,可能有的函数就没有了,比如 bit中的math.mod 函数,5.1 之后就改为 fmod()了,但是当时引入的还是之前的版本,就报错了,报错了,但是还找了好久的错误,也是醉了。这些可以参考 lua官网的发布说...

weixin_30839881的博客 4277

lua-lcurl 错误:lcurl.so:1: unexpected symbol near 'char(127)'

完整错误信息: [error] 10740#0: *117 lua entry thread aborted: runtime error: error loading module 'lcurl' from file '/usr/local/lib/lua/5.3/lcurl.so':/usr/local/lib/lua/5.3/lcurl.so:1: unexpected symbol n...

潘广宇的博客 2851
上一篇: 前端解析 excel docx
下一篇: node 操作word excel
weixin_30681615
博客等级 码龄11年 120粉丝 1380原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值