Skip to content

await_any_or_fail deadlocks when only later futures complete #103

Closed

Description

@EdmondDantes

Repro

<?php
use Async\Future;
use Async\FutureState;
use function Async\spawn;
use function Async\await_all;

$s1 = new FutureState();
$s2 = new FutureState();
$f1 = new Future($s1);
$f2 = new Future($s2);

$P = spawn(fn() => $s2->complete(2));      // completes F2
$A = spawn(fn() => \Async\await_any_or_fail([$f1, $f2]));
await_all([$P, $A]);

Expected: A receives 2, both coroutines finish.

Actual: deadlock. Output:

=== DEADLOCK REPORT START ===
Coroutines waiting: 2, active_events: 0

Coroutine 6 spawned at :0, suspended at repro.php:19 (main)
  waiting for: Coroutine 10 ...
Coroutine 10 spawned at repro.php:15, suspended at repro.php:16
  waiting for:

If the producer completes the first future ($s1->complete(1)) instead, the test passes — the awaiter wakes up and returns 1. So await_any_or_fail appears to register a listener only on the first trigger of the iterable, ignoring the rest.

Where it was found

fuzzy_tests/await/await_any.feature, Examples row which=F2, deterministic
under FIFO and every random scheduler tested. Found by the chaos harness
introduced in #102.

Activity

  1. added
    bug
    on May 9, 2026
  2. added a commit that references this issue on May 9, 2026
  3. EdmondDantes commented on May 9, 2026

    @EdmondDantes
    ContributorAuthor

    Investigation: bug is Future-specific

    Existing tests/await/*.phpt for await_any* exclusively pass arrays of
    Coroutines as triggers — none of them combine await_any_or_fail with
    Async\Future instances. That is why the bug has slipped through.

    Verified the symmetric case with coroutines works:

    $c1 = spawn(fn() => { suspend(); suspend(); suspend(); return "first"; });  // late
    $c2 = spawn(fn() => "second");                                                // wins
    $w  = spawn(fn() => echo \Async\await_any_or_fail([$c1, $c2]));
    await_all([$c1, $c2, $w]);
    // prints "second" — correct

    So the trigger-registration path for Future in await_any_or_fail
    appears not to be wired up symmetrically with the Coroutine path. The
    listener for the second (and presumably any later) Future trigger is
    either not installed or never fires.

    Suggests adding a phpt that uses Future triggers for every
    await_any* / await_first* variant.

  4. added this to the TrueAsync 0.7.0 milestone on May 9, 2026
  5. added a commit that references this issue on May 9, 2026
  6. self-assigned this
    on May 9, 2026
  7. added a commit that references this issue on May 9, 2026
  8. added a commit that references this issue on May 9, 2026
  9. added a commit that references this issue on May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions