Skip to content

Segmentation fault/fiber exceptions dependent on destruction order on 8.4 #105

Open
@danog

Description

@danog

A variety of issues ranging from segmentation faults to "FiberError: Cannot resume a fiber that is not suspended" are emitted if:

  • Running on 8.4+ AND
  • Running async logic in a __destruct method of a given class "a" AND
  • The garbage collector invokes the __destruct of the event loop before invoking the __destruct method of class "a"

Reproducer:

<?php

use Revolt\EventLoop;
use Revolt\EventLoop\Driver\StreamSelectDriver;

require 'vendor/autoload.php';

final class a {
    private static self $a;
    public static function getInstance(): self {
        return self::$a ??= new self;
    }

    public function __destruct()
    {
        var_dump("Destroying ".self::class);
        $suspension = EventLoop::getSuspension();
        EventLoop::delay(1.0, $suspension->resume(...));
        $suspension->suspend();
        var_dump("Finished ".self::class);
    }
}

EventLoop::defer(function () {
    var_dump("start");
});

a::getInstance();

EventLoop::run();

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