resty-lock inoperative in init_worker_by_lua_file
hi,agentzh I used lock:lock on init_worker_by_lua_file,but inoperative. here is my code `local resty_lock = require "resty.lock" local lockOpts = {["exptime"]="5",["timeout"]="0"} local lock, err = resty_lock:new("MY_LOCKS",lockOpts) if not lock then ngx.log(ngx.ERR,"failed to create lock:"..tostring(err)) return end
local elapsed, err = lock:lock('lock_key') if not elapsed then ngx.log(ngx.DEBUG,"failed to acquire the lock: "..tostring(err)) return else ngx.log(ngx.DEBUG,"get lock success") return end )`
My nginx has 4 workers and i set timeout=0 for get lock operation,but still display 4 'get lock success'
@panjunDev This is a known limitation. See https://github.com/openresty/lua-resty-lock/#limitations
hi, agentzh i have 4 worker process, i need one to load data, before this worker completed load data, other workers should not work(can't process request). how can i do it?
@fengshenyun Sounds like you should really load the data in the init_by_lua* handler instead (i.e., in the master process before forking off workers).
because of i need load data from a http server, init_by_lua* is not allow do this.
@fengshenyun You can try using the blocking LuaSocket library to do this as long as its timeout protection is good enough. It does not matter to block in the master process for a bit (just not too long). But yeah, we'll eventually enable the cosocket API in the context of init_by_lua* context. Before that, you can use the blocking approach as a workaround.