8000 [Lock] SemaphoreStore catching exception from sem_get by Triplkrypl · Pull Request #45737 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Lock] SemaphoreStore catching exception from sem_get #45737

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

Merged
merged 1 commit into from
Mar 18, 2022
Merged
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
8 changes: 4 additions & 4 deletions src/Symfony/Component/Lock/Store/SemaphoreStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ private function lock(Key $key, bool $blocking)
}

$keyId = unpack('i', md5($key, true))[1];
$resource = sem_ 8000 get($keyId);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the ErrorException originates from a php warning
instead, I suggest using this (and removing the new method):

$resource = @sem_get($keyId);
$acquired = $resource && @sem_acquire($resource, !$blocking);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was not sure if @ operator can suspend exceptions, this looks nice. I go change this.

$acquired = @sem_acquire($resource, !$blocking);
$resource = @sem_get($keyId);
$acquired = $resource && @sem_acquire($resource, !$blocking);

while ($blocking && !$acquired) {
$resource = sem_get($keyId);
$acquired = @sem_acquire($resource);
$resource = @sem_get($keyId);
$acquired = $resource && @sem_acquire($resource);
}

if (!$acquired) {
Expand Down
0