Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 172bf0f

Browse files
bug #45737 [Lock] SemaphoreStore catching exception from sem_get (Triplkrypl)
This PR was merged into the 4.4 branch. Discussion ---------- [Lock] SemaphoreStore catching exception from sem_get | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no We use on project symfony/lock and I found exception in our monitoring from `sem_get` PHP function. Function `sem_get` is called before `sem_acquire` so resource is not locked and `sem_get` function call can run in same time as some code with locked resource in another process where removing semaphpore going on by function `sem_remove`. PHP: 7.4.13 symfony/lock: 5.3.4 Exceptions: `Symfony\Component\Lock\Exception\LockAcquiringException` Failed to acquire the "some_our_resource_key" lock. `ErrorException` sem_get(): failed for key 0xffffffffb8cf1ec4: Identifier removed Commits ------- 53f473f ignoring exception from sem_get in SemaphoreStore Lock component, preventing of error: identifier removed
2 parents 0df1764 + 53f473f commit 172bf0f

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/Symfony/Component/Lock/Store/SemaphoreStore.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ private function lock(Key $key, bool $blocking)
6464
}
6565

6666
$keyId = unpack('i', md5($key, true))[1];
67-
$resource = sem_get($keyId);
68-
$acquired = @sem_acquire($resource, !$blocking);
67+
$resource = @sem_get($keyId);
68+
$acquired = $resource && @sem_acquire($resource, !$blocking);
6969

7070
while ($blocking && !$acquired) {
71-
$resource = sem_get($keyId);
72-
$acquired = @sem_acquire($resource);
71+
$resource = @sem_get($keyId);
72+
$acquired = $resource && @sem_acquire($resource);
7373
}
7474

7575
if (!$acquired) {

0 commit comments

Comments
 (0)