Skip to content
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

fix: fix posix semaphore blocks thread when there is no space left on device #29

Merged
merged 1 commit into from
Aug 3, 2024
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
6 changes: 3 additions & 3 deletions src/PosixSemaphore.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,17 +222,17 @@
}

\set_error_handler(static function (int $errno, string $errstr): bool {
if (\str_contains($errstr, 'Failed for key')) {
if (!\str_contains($errstr, 'No space left on device') && \str_contains($errstr, 'Failed for key')) {
return true;
}

throw new SyncException('Failed to create semaphore: ' . $errstr, $errno);
});

try {
$id = self::$nextId;

do {
$id = self::$nextId;
Copy link
Member

Choose a reason for hiding this comment

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

@trowski Could you have another look here? LGTM.


while (\msg_queue_exists($id)) {
$id = self::$nextId = self::$nextId % self::MAX_ID + 1;
}
Expand All @@ -254,7 +254,7 @@
\restore_error_handler();
}

$this->key = $id;

Check failure on line 257 in src/PosixSemaphore.php

View workflow job for this annotation

GitHub Actions / PHP 8.1

PossiblyUndefinedVariable

src/PosixSemaphore.php:257:22: PossiblyUndefinedVariable: Possibly undefined variable $id defined in try block (see https://psalm.dev/018)

Check failure on line 257 in src/PosixSemaphore.php

View workflow job for this annotation

GitHub Actions / PHP 8.2

PossiblyUndefinedVariable

src/PosixSemaphore.php:257:22: PossiblyUndefinedVariable: Possibly undefined variable $id defined in try block (see https://psalm.dev/018)

// Fill the semaphore with locks.
while (--$maxLocks >= 0) {
Expand Down
Loading