-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
[Lock] Remove released semaphore #27357
Conversation
Can we have tests reproducing the issue ? AFAIK, all tests of the SemaphoreStore are green with the existing implementation, so having it non-working means that the testsuite is not covering things properly. |
and you worked on an outdated version of Symfony master (or you targeted the wrong branch when opening the PR), as this conflicts. |
2bdfb09
to
97026c7
Compare
Added a test case and fix target branch |
I'd rather see a test about the behavior of the store (to prevent the bug beign reported) rather than a test enforcing this specific implementation (which does not prove that this implementation is the right one, but forbids replacing it) |
@stof unless I missed a point, the bug reported is The test asserts that amount of semaphores used on the OS does not increase when the lock is acquired then released, regardless of the implementation. An other way to test it would be to reproduce the reported bug. Meaning either
Do you see another way to test the behavior? |
Is |
Wouldn't say so.
If your application can control the amount of distinguished resource, you should For the record, we have exactly the same issue with the original implementation of |
while ($blocking && !$acquired) { | ||
$resource = sem_get($keyId); | ||
$acquired = @sem_acquire($resource, !$blocking); | ||
} | ||
} | ||
|
||
if (!$acquired) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wondering: can this happen at all now? do we need some sort of timeout in the while above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, if \PHP_VERSION_ID >= 50601
and !$blocking
|
||
while ($blocking && !$acquired) { | ||
$resource = sem_get($keyId); | ||
$acquired = @sem_acquire($resource, !$blocking); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the value of $blocking is known here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
97026c7
to
0d2fc31
Compare
$acquired = sem_acquire($resource, !$blocking); | ||
$acquired = @sem_acquire($resource, !$blocking); | ||
|
||
while ($blocking && !$acquired) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This loop can be moved outside of the if/else
} else { | ||
$acquired = sem_acquire($resource, !$blocking); | ||
$acquired = @sem_acquire($resource, !$blocking); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By swapping the order of the if/else, we can simplify the condition: if (PHP>=...) elseif !$blovking throw
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
0d2fc31
to
77b9f90
Compare
Thank you @jderusse. |
This PR was merged into the 3.4 branch. Discussion ---------- [Lock] Remove released semaphore | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #27356 | License | MIT | Doc PR | NA This PR remove the semaphore with `sem_remove`. By removing without releasing the semaphore, all pending blocking acquiring will fail that's why the acquire method has also been update to handle such case Commits ------- 77b9f90 Remove released semaphore
I do not know if there is anything to do with this topic, but in a console command I do this: ``
`` And i have this warning:
I'm using SF3.4. Thanks. |
This PR remove the semaphore with
sem_remove
. By removing without releasing the semaphore, all pending blocking acquiring will fail that's why the acquire method has also been update to handle such case