lua-zlib icon indicating copy to clipboard operation
lua-zlib copied to clipboard

_G write guard whines about zlib being global and could cause race conditions

Open Raw1mage opened this issue 6 years ago • 5 comments

when I do this

    local zlib = require ("zlib")

nginx error log would show: [warn] 30914#30914: *24397 [lua] _G write guard:12: writing a global lua variable ('zlib') which may lead to race conditions between concurrent requests, so prefer the use of 'local' variables stack traceback: [C]: at 0x7f165255b755 [C]: in function 'require'

any light ?

Raw1mage avatar Aug 01 '19 05:08 Raw1mage

Maybe because we use the old luaL_register function when we should be using luaL_setfuncs?

https://github.com/brimworks/lua-zlib/blob/master/lua_zlib.c#L1263

Feel free to issue a pull request if this change fixes your issue.

Thanks! -Brian

brimworks avatar Aug 01 '19 13:08 brimworks

I had the same issue and could fix it by replacing the luaL_register with this:

lua_newtable(L);
luaL_setfuncs(L, zlib_functions, 0);

It works when importing from openresty (luajit), but not from standalone Lua 5.1

davidguerreroprezi avatar Aug 02 '19 13:08 davidguerreroprezi

Perhaps a little "macro magic" could solve this problem? Pull requests are welcomed :).

brimworks avatar Aug 02 '19 22:08 brimworks

I had the same issue with lua-zlib-1.2

a652 avatar May 27 '20 14:05 a652

If you use OpenResty, maybe can refer to this openresty/openresty#510 as a workaround.

howiezhao avatar Jun 10 '22 09:06 howiezhao