Skip to content

A cancel() that arrives while a shield()ed body is parked in delay() wakes it early instead of letting it finish #399

Closed

Description

@blacktrs

Summary

A cancel() that arrives while a shield()ed body is parked in delay() wakes it early instead of letting it finish.

Repro

<?php
use function Async\async;
use function Async\spawn;
use function Async\shield;
use function Async\delay;

async(function () {
    $t0 = hrtime(true);
    $t = spawn(function () use ($t0) {
        try {
            shield(function () use ($t0) {
                delay(0.2);
                echo 'shield body finished after ', (hrtime(true) - $t0) >= 190_000_000 ? 'the full delay' : 'an early wake-up', "\n";
            });
        } catch (\Async\CancelledException $e) {
        }
    });
    delay(0.02);
    $t->cancel();
    try { $t->await(); } catch (\Throwable $e) {}
});

Expected (php)

shield body finished after the full delay

Actual (manticore 515a500a, Darwin arm64)

shield body finished after an early wake-up

Tracking

Known-bug repro: tests/aot/repro/wrong/shield_body_woken_early_by_cancel.php — bash tests/aot/xfail.sh -k shield_body_woken_early_by_cancel reports XFAIL while this is open and XPASS once it is fixed; then move the repro into tests/aot/cases/ and close this issue.

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

    bugwrong-answer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions