你可以试试增加一个
init_by_lua_block {
-- suppress the global var warning
local _ = require "comm"
}
init_by_lua_block 仅执行一次,不会抛出这个warn.
require 有 cache,后面的require 就直接用了,不会再加载了。也就不会再报这个warn了
希望能帮到你
--
jqliu
On Tuesday, February 4, 2020 at 4:41:58 PM UTC+8, 李建涛 wrote:
更正一下, 帖子里贴的warn信息有误, 这里应该是'comm'模块报的。
[warn] 31335#0: *1040117 [lua] _G write guard:12: writing a global lua variable ('comm') which may lead to race conditions between concurre
nt requests, so prefer the use of 'local' variables
在 2020年2月4日星期二 UTC+8下午4:38:38,李建涛写道:
请问这个问题怎么解决? 更新到最新的openresty后出现的。
[warn] 31335#0: *1040117 [lua] _G write guard:12: writing a global lua variable ('uls') which may lead to race conditions between concurren
t requests, so prefer the use of 'local' variables
lua代码:
local comm = require "comm"
comm是一个封装的c++ so,
代码如下:
int KEY_HASH(lua_State* L)
{
size_t iKeyLen = 0;
const char* pKeyValue = luaL_checklstring(L,1, &iKeyLen);
int iHashBase = luaL_checknumber(L,2);
if (pKeyValue == NULL)
{
return 1;
}
unsigned long long ullKey = hash(pKeyValue,iKeyLen,iHashBase);
lua_pushnumber(L, ullKey);
return 1;
}
static luaL_Reg mylibs[] = {
{"KEY_HASH", KEY_HASH},
{NULL, NULL}
};
int luaopen_comm(lua_State* L)
{
luaL_register(L, "comm", mylibs);
return 1;
}
事实上, require所有的封装的c++动态库都会出现这个 warn.