openresty / lua-resty-mysql

Nonblocking Lua MySQL driver library for ngx_lua or OpenResty
708 stars 236 forks source link

lua entry thread aborted: runtime error: /usr/local/openresty/lualib/resty/mysql.lua:571: bad request #109

Closed liuhengloveyou closed 4 years ago

liuhengloveyou commented 4 years ago

报错: 2020/09/14 10:27:58 [error] 22975#22975: *38542253 lua entry thread aborted: runtime error: /usr/local/openresty/lualib/resty/mysql.lua:571: bad request stack traceback: coroutine 0: [C]: in function 'connect' /usr/local/openresty/lualib/resty/mysql.lua:571: in function 'connect' /usr/local/openresty/nginx/lualib/cache.lua:39: in function 'mysqlQuery' /usr/local/openresty/nginx/lualib/cache.lua:77: in function 'loadAndCache' /usr/local/openresty/nginx/lualib/cache.lua:114: in function 'get'

代码如下: `function _M.mysqlQuery(dbName, sql) if dbName == nil or dbName == ngx.null then return end if sql == nil or sql == ngx.null then return end if nil == require("conf").mysqlConfig[dbName] then return end local ok, err, errcode, sqlstate = _M.db:connect{ host = require("conf").mysqlConfig[dbName].host, port = require("conf").mysqlConfig[dbName].port, database = require("conf").mysqlConfig[dbName].database, user = require("conf").mysqlConfig[dbName].user, password = require("conf").mysqlConfig[dbName].password, charset = "utf8", max_packet_size = 1024 * 1024, } if not ok then ngx.log(ngx.ERR, "failed to connect mysql: ", err, ": ", errcode, " ", sqlstate) return end

local res, err, errcode, sqlstate = _M.db:query(sql) if not res then ngx.log(ngx.ERR, "bad result: ", err, ": ", errcode, ": ", sqlstate, ".") return res, err end

-- put it into the connection pool of size 100, -- with 100 seconds max idle timeout local ok, err = _M.db:set_keepalive(100000, 100) if not ok then ngx.log(ngx.ERR, "failed to set mysql keepalive: ", err) -- return end

return res end`