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

PosixSemaphore blocks when there is no space left on device. #28

Closed
azjezz opened this issue May 30, 2024 · 0 comments · Fixed by #29
Closed

PosixSemaphore blocks when there is no space left on device. #28

azjezz opened this issue May 30, 2024 · 0 comments · Fixed by #29

Comments

@azjezz
Copy link
Sponsor Contributor

azjezz commented May 30, 2024

The following code:

$semaphore = PosixSemaphore::create(1, permissions: 0600);

will block the current thread forever if there is "no space left on device".

the reason for this seems to be coming from here:

sync/src/PosixSemaphore.php

Lines 224 to 230 in 375ef5b

\set_error_handler(static function (int $errno, string $errstr): bool {
if (\str_contains($errstr, 'Failed for key')) {
return true;
}
throw new SyncException('Failed to create semaphore: ' . $errstr, $errno);
});

the error message for when max queue ids is reached is msg_get_queue(): Failed for key 0x00000000: No space left on device ( replacing 0x00000000 with the currently being tested id ).

which amphp skips in attempt to try another ID.

but there seems to be another problem in this logic:

sync/src/PosixSemaphore.php

Lines 232 to 255 in 375ef5b

try {
$id = self::$nextId;
do {
while (\msg_queue_exists($id)) {
$id = self::$nextId = self::$nextId % self::MAX_ID + 1;
}
/** @psalm-suppress TypeDoesNotContainType */
$queue = \msg_get_queue($id, $permissions);
/** @psalm-suppress RedundantCondition */
if ($queue) {
/** @psalm-suppress InvalidPropertyAssignmentValue */
$this->queue = $queue;
$this->initializer = \getmypid();
break;
}
++self::$nextId;
} while (true);
} finally {
\restore_error_handler();
}

If an identifier exists, but there is no space left on device, the id will not change, Amphp will keep trying to create the queue for the same ID over and over again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant