openresty / openresty/lua-nginx-module
Sharing changable data inside a worker and timers
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 11.8k
- Forks
- 2.1k
- Avg merge
- 6h 1m
- Merged PRs (30d)
- 6
Description
I have read this part of the documentation https://github.com/openresty/lua-nginx-module#data-sharing-within-an-nginx-worker
Which is what I need, but I also require that a variable inside a module I define, is accessed within the worker (request handlers). But it is updated through a timer.every mechanism so something like this.
init_worker_by_lua_block : Create timer to update the variable.
server_rewrite_by_lua_block: Use the variable. (I chose server_rewrite because I thought it is earlier stage than rewrite)
The variable is an integer, so I am asking if this usage is subject to race condition. It's an integer, so I could easily make it an atomic operation to set/get it in C (without locks). But that means writing an Nginx module. I was wondering if this was also possible with Lua.
Edit: Maybe a clever trick like employing https://www.lua.org/manual/2.1/subsection3_5_2.html (I have no experience with it), to retain/implement the atomic ability of setting and reading an integer in C.
Edit_2: Would making the variable not global (_M), but accessed through getter/setter functions in the module, but kept in the lua module as local var = 3; help? Like helping with concurrency and avoiding table look up.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read the linked data-sharing documentation and the init_worker_by_lua_block and server_rewrite_by_lua_block entry points first. Determine whether timer updates and request-handler reads are supported, including the proposed local getter/setter approach; done would be a documented, project-backed answer or clarified guidance.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua, nginx
- Domain
- backend
- Issue type
- Documentation
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100