-
Notifications
You must be signed in to change notification settings - Fork 272
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
[bug] semaphore not released on exit/premature #337
Comments
I feel like this is a generic issue in OpenResty, not just semaphores. Sleeps (or timers) prevent graceful exit, and they are not woken up on quit/reload. Same issue is with It would be better to prematurely woke up any sleeps/timers on |
If, in the above example, I change: sema:post(1000) into sema:post(1000)
ngx.timer.at(0, function()
ngx.log(ngx.WARN,"please ignore")
end) then it works as expected. |
@dndx and I have been doing some cechking on this. in short, as documented, |
@javierguerragiraldez just tested, and indeed just yielding seems enough. So in the example above this is the simplest fix: ngx.timer.at(30, function(premature)
-- release semaphore
sema:post(1000)
if premature then
print "released prematurely"
ngx.sleep(0) -- FIXME: required to properly release the waiting threads
else
print "released upon expiry"
end
end) |
this seems to have been fixed. Can no longer reproduce on |
consider this code:
Semaphore waits for 45 seconds. A timer posts resources after 30 seconds.
When I run the code and wait more than 30 seconds, I get (as expected) this in the logs:
After 30 seconds the semaphore is released.
However, when I send a QUIT signal during the first 30 seconds I get this (unexpected) result:
at
15:50:13
the resources are posted, but at15:50:52
(39 seconds later) the semaphore times out.Version info:
The text was updated successfully, but these errors were encountered: