Skip to content

bugfix: Semaphore not cleaned up on request timeout #502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions lib/ngx/semaphore.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ if subsystem == 'http' then
int ngx_http_lua_ffi_sema_new(ngx_http_lua_sema_t **psem,
int n, char **errmsg);

int ngx_http_lua_ffi_sema_post(ngx_http_lua_sema_t *sem, int n);
int ngx_http_lua_ffi_sema_post(ngx_http_request_t *r,
ngx_http_lua_sema_t *sem, int n);

int ngx_http_lua_ffi_sema_count(ngx_http_lua_sema_t *sem);

Expand All @@ -72,7 +73,8 @@ elseif subsystem == 'stream' then
int ngx_stream_lua_ffi_sema_new(ngx_stream_lua_sema_t **psem,
int n, char **errmsg);

int ngx_stream_lua_ffi_sema_post(ngx_stream_lua_sema_t *sem, int n);
int ngx_stream_lua_ffi_sema_post(ngx_stream_lua_request_t *r,
ngx_stream_lua_sema_t *sem, int n);

int ngx_stream_lua_ffi_sema_count(ngx_stream_lua_sema_t *sem);

Expand Down Expand Up @@ -167,6 +169,11 @@ function _M.post(self, n)
error("not a semaphore instance", 2)
end

local r = get_request()
if not r then
error("no request found")
end

local cdata_sem = self.sem

local num = n and tonumber(n) or 1
Expand All @@ -175,7 +182,7 @@ function _M.post(self, n)
end

-- always return NGX_OK
ngx_lua_ffi_sema_post(cdata_sem, num)
ngx_lua_ffi_sema_post(r, cdata_sem, num)

return true
end
Expand Down