openresty / openresty/lua-nginx-module

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

Open
#2,277 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
11.8k
Forks
2.1k
Avg merge
6h 1m
Merged PRs (30d)
6

Description

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?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The report names the Lua Variable Scope documentation and two content_by_lua_block locations; start by reading that section and comparing the two LuaJIT build configurations. Reproduce the /set and / request behavior in both builds, then document whether the differing global-environment behavior is expected and whether the documentation needs correction.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua, nginx
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.