发现lua-resty-mysql的奇怪问题

118 views
Skip to first unread message

lhmwzy

unread,
Dec 20, 2013, 10:53:57 PM12/20/13
to open...@googlegroups.com
最小示例如下:

conf/lua目录下有如下文件,名为testdb.lua

local mysql = require "resty.mysql"
local db = mysql:new()
db:set_timeout(300000)

local ok, err, errno, sqlstate = db:connect({
host = "127.0.0.1",
port = "3306",
database = "test",
user = "root",
password = "passwd",
max_packet_size=1048})

if not ok then
ngx.say("failed to connect: ", err, ": ", errno, " ", sqlstate)
return
end
local query
query="select * from user limit 50 "
res, err, errno, sqlstate = db:query(query)
if not res then
ngx.say("bad result: ", err, ": ", errno, ": ", sqlstate, ".")
return
end

local cjson = require "cjson"
ngx.say(cjson.encode(res))

nginx conf的配置中加

location = /testdb {
content_by_lua_file 'conf/lua/testdb.lua';
}

mysql数据库中user表的结构为
TABLE `user` (
`id` int(20) NOT NULL AUTO_INCREMENT,
`user` varchar(800) DEFAULT NULL,
`passwd` varchar(20) DEFAULT NULL,
`email` varchar(50) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=6070422 DEFAULT CHARSET=utf8;


通过浏览器访问 http://xxxx/testdb
刷新几次后,会发现只显示
{"user":"zxxx ","id":1},{"user":"xxxx ","id":2}.........
正常的应该显示
[{"user":"xx ","email":"x...@xxx.net","passwd":"12344321","id":1},{"user":"xxxx
","email":"xxx...@163.com","passwd":"xxx","id":2}..........


openresty 1.4.3.9


nginx/sbin/nginx -V
nginx version: ngx_openresty/1.4.3.9
built by gcc 4.2.1 20070719 [FreeBSD]
TLS SNI support enabled
configure arguments: --prefix=/usr/local/openresty/nginx
--add-module=../ngx_devel_kit-0.2.19
--add-module=../echo-nginx-module-0.50
--add-module=../xss-nginx-module-0.04
--add-module=../ngx_coolkit-0.2rc1
--add-module=../set-misc-nginx-module-0.23
--add-module=../form-input-nginx-module-0.07
--add-module=../encrypted-session-nginx-module-0.03
--add-module=../srcache-nginx-module-0.24
--add-module=../ngx_lua-0.9.3
--add-module=../headers-more-nginx-module-0.24
--add-module=../array-var-nginx-module-0.03
--add-module=../memc-nginx-module-0.14
--add-module=../redis2-nginx-module-0.10
--add-module=../redis-nginx-module-0.3.7
--add-module=../auth-request-nginx-module-0.2
--add-module=../rds-json-nginx-module-0.13
--add-module=../rds-csv-nginx-module-0.05
--with-ld-opt=-Wl,-rpath,/usr/local/openresty/luajit/lib
--with-http_ssl_module


uname -a:
FreeBSD lhm.com 8.2-RELEASE FreeBSD 8.2-RELEASE #0: Fri Feb 18
02:24:46 UTC 2011
ro...@almeida.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC i386

lhmwzy

unread,
Dec 21, 2013, 12:25:22 AM12/21/13
to open...@googlegroups.com
换成1.4.3.1,没有问题

2013/12/21 lhmwzy <lhm...@gmail.com>:

Yichun Zhang (agentzh)

unread,
Dec 21, 2013, 12:41:53 AM12/21/13
to openresty
Hello!

On Fri, Dec 20, 2013 at 9:25 PM, lhmwzy wrote:
> 换成1.4.3.1,没有问题
>

多谢报告!

请尝试:

1. 使用 openresty 1.4.3.6 时看看是否还能复现问题。

2. 使用 openresty 1.4.3.9 时在 nginx.conf 的 http {} 块里添加一行

init_by_lua 'jit.off()';

看看是否还能复现问题。

另外,你是否有使用 resty.core 模块?即你是否有 require "resty.core"?

Regards,
-agentzh

lhmwzy

unread,
Dec 21, 2013, 1:05:16 AM12/21/13
to open...@googlegroups.com
1.4.3.6无此问题,不论jit.off()是否开启。

1.4.3.9在加上jit.off()时无此问题,不加就有问题。

resty.core加与不加,无影响。
> --
> --
> 邮件来自列表“openresty”,专用于技术讨论!
> 订阅: 请发空白邮件到 openresty...@googlegroups.com
> 发言: 请发邮件到 open...@googlegroups.com
> 退订: 请发邮件至 openresty+...@googlegroups.com
> 归档: http://groups.google.com/group/openresty
> 官网: http://openresty.org/
> 仓库: https://github.com/agentzh/ngx_openresty
> 教程: http://openresty.org/download/agentzh-nginx-tutorials-zhcn.html

Yichun Zhang (agentzh)

unread,
Dec 21, 2013, 2:22:42 AM12/21/13
to openresty
Hello!

2013/12/20 lhmwzy:
> 1.4.3.6无此问题,不论jit.off()是否开启。
>
> 1.4.3.9在加上jit.off()时无此问题,不加就有问题。
>
> resty.core加与不加,无影响。
>

多谢反馈!

看起来像是 LuaJIT v2.1 的 JIT 编译器里的一个 bug. 我明天先尝试在我本地复现一下你的这个问题 :) 如果我复现不了,我再找你帮忙,呵呵。

Best regards,
-agentzh

lhmwzy

unread,
Dec 22, 2013, 1:34:55 AM12/22/13
to open...@googlegroups.com
可以重现吗?

Yichun Zhang (agentzh)

unread,
Dec 22, 2013, 1:45:03 AM12/22/13
to openresty
Hello!

2013/12/21 lhmwzy:
> 可以重现吗?
>

我忘了问你的 SQL 查询返回的结果集有多少行呢?另外,你是在 FreeBSD 9 上面吗?体系结构是 x86_64?

我今天在弄 LuaJIT 2.1 里的一个会引起段错误的 bug,不确定是否和你的问题有关。我明天再尝试复现哈。

Thanks!
-agentzh

lhmwzy

unread,
Dec 22, 2013, 1:53:04 AM12/22/13
to open...@googlegroups.com
结果大概是50行
我是FreeBSD 8.2,X86
在邮件的中的uname,我提供了操作系统的信息

lhmwzy

unread,
Dec 22, 2013, 6:56:03 PM12/22/13
to open...@googlegroups.com
如果返回结果是5行,经多次刷新后,也会出现此问题
刷新的次数要比50行的多

Yichun Zhang (agentzh)

unread,
Dec 26, 2013, 5:37:43 PM12/26/13
to openresty
Hello!

2013/12/22 lhmwzy:
> 如果返回结果是5行,经多次刷新后,也会出现此问题
> 刷新的次数要比50行的多
>

正如你线下分析的那样,这个问题确实是 LuaJIT v2.1 中的 table.new() 在 i386 系统上的一个 bug. Mike
Pall 刚刚已经在 git 仓库的 v2.1 分支上提交了一个补丁,修正了此问题:

http://repo.or.cz/w/luajit-2.0.git/commit/c1328e97957ec2fdd8c27474cbd3fecb9f204a6d

多谢报告!

Best regards,
-agentzh

lhmwzy

unread,
Dec 26, 2013, 6:51:17 PM12/26/13
to open...@googlegroups.com
确认有效
仅几个字就解决了。。。。
Reply all
Reply to author
Forward
0 new messages