Skip to content

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

Description

@azjezz

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.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions