openresty / lua-nginx-module

Embed the Power of Lua into NGINX HTTP servers
https://openresty.org/
11.34k stars 2.03k forks source link

Why is global environment of each lua handler not isolated when OpenResty's LuaJIT is used? #2277

Open Rcyyy opened 10 months ago

Rcyyy commented 10 months ago

OpenResty version used in my issue: 1.21.4.3

It's said in the section Lua Variable Scope that each request handler has its own set of Lua global variables.But It's not so in the source code here:

openresty_luajit

Only the version built without OpenResty's LuaJIT(eg. without the micro OPENRESTY_LUAJIT) can have a new table as global environment in each lua coroutine.

I also did experiment on two versions of OpenResty, one was built with OpenResty's LuaJIT and the other is built with official version of LuaJIT. I created two locations to set and get global variable like this:

location = /set {
    content_by_lua_block { key=1 ngx.say("set global key!") }
}
location / {
    content_by_lua_block { ngx.say(key or "nil")}
}

In the result, the OpenResty's LuaJIT version successfully got the gloabl 'key' and the other version did't.

So why does lua-nginx has this global environment setting with different luajit version? Why doesn't OpenResty's LuaJIT need isolated global environment?