diff options
author | Christian Pointner <equinox@spreadspace.org> | 2014-10-18 00:32:21 +0200 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2014-10-18 00:32:21 +0200 |
commit | f3c1a77d7a4814f3dd3be5dae6d530471a8d58a5 (patch) | |
tree | d3551ea4333ab65820a6e96685649cfb76283d99 /src/daq/nginx-lua/s5-nginx-fetch.lua | |
parent | added proposal for protocol upgrade (diff) |
moved to resty-lock for fetchold-lua-ngx
Diffstat (limited to 'src/daq/nginx-lua/s5-nginx-fetch.lua')
-rw-r--r-- | src/daq/nginx-lua/s5-nginx-fetch.lua | 41 |
1 files changed, 15 insertions, 26 deletions
diff --git a/src/daq/nginx-lua/s5-nginx-fetch.lua b/src/daq/nginx-lua/s5-nginx-fetch.lua index 8bfcf07..8821094 100644 --- a/src/daq/nginx-lua/s5-nginx-fetch.lua +++ b/src/daq/nginx-lua/s5-nginx-fetch.lua @@ -33,52 +33,41 @@ -- Install this by adding the following to your nginx.conf -- -- location /sfive { --- allow localhost; +-- allow 127.0.0.1; +-- allow ::1; -- deny all; -- --- lua_check_client_abort on; -- content_by_lua_file '/path/to/s5-nginx-fetch.lua'; -- } -- -local sfive = ngx.shared.sfive - -local function fetch_cleanup() - ngx.log(ngx.INFO, "SFive(fetch): cleanup fetch") - sfive:delete("fetch:connected") -end - -local ok, err, force = sfive:add("fetch:connected", 1) --- TODO: race condition: when client disconnects here we won't free up the singleton... +local lock = locks:new("sfive_locks", { exptime = nil, timeout = 0.001 }) +local ok, err = lock:lock("fetch") if not ok then - if err == "exists" then + if err == "timeout" then ngx.exit(ngx.HTTP_SERVICE_UNAVAILABLE) else - ngx.log(ngx.ERR, "SFive(fetch): failed to set connected flag: " .. err) + ngx.log(ngx.ERR, "SFive(fetch): failed to acquire fetch lock: " .. err) ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR) end else - local ok, err = ngx.on_abort(fetch_cleanup) - if not ok then - ngx.log(ngx.ERR, "SFive(fetch): failed to register the on_abort callback: ", err) - ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR) - end - ngx.log(ngx.INFO, "SFive(fetch): client connected") - - local sfive_log = ngx.shared.sfive_log + local sfive_data = ngx.shared.sfive_data while true do - logs = sfive_log:get_keys() + logs = sfive_data:get_keys() for i, k in ipairs(logs) do - local ok, err = ngx.say(sfive_log:get(k)) + local ok, err = ngx.say(sfive_data:get(k)) if not ok then - ngx.log(ngx.ERR, "SFive(fetch): failed to register the on_abort callback: ", err) + ngx.log(ngx.ERR, "SFive(fetch): failed to send data set: ", err) break end - sfive_log:delete(k) + sfive_data:delete(k) end ngx.flush() ngx.sleep(0.1) end - fetch_cleenup() + ok, err = lock:unlock("fetch") + if not ok then + ngx.log(ngx.ERR, "SFive(fetch): unlock error: " .. err) + end end |