Skip to content

Segfault / Assertion failed: (p->refcount > 0), function zend_gc_delref, file zend_types.h, line 1342 #15108

Closed
@kelunik

Description

@kelunik

Description

The following code:

#!/usr/bin/env php
<?php

require __DIR__ . '/../vendor/autoload.php';

use Amp\Pipeline\ConcurrentIterator;
use Amp\Pipeline\Pipeline;
use Amp\Pipeline\Queue;

class Wrapper implements \IteratorAggregate
{
    public function __construct(private readonly iterable $iterable)
    {
    }

    public function getIterator(): \Generator
    {
        yield from $this->iterable;
    }
}

$queue = new Queue();
$queue->pushAsync('foo');
$pipeline = Pipeline::fromIterable(new Wrapper($queue->iterate()));

function foo(ConcurrentIterator $iterator)
{
    $iterator->continue();

    return $iterator->getValue();
}

foo($pipeline->getIterator());

Needs https://github.com/amphp/pipeline/tree/66c095673aa5b6e689e63b52d19e577459129ab3 for reproduction.

Resulted in this output:

➜ php examples/gc.php 
[1]    13539 segmentation fault  php examples/gc.php

But I expected this output instead:

➜ php examples/gc.php 

My original test case looked like this in https://github.com/amphp/redis/blob/0b3f38d4f3cfd9d5c576d89d2002f82235c426a8/test/PubSubTest.php resulting in an assertion error. While trying to reduce the test case for reporting, I encountered the above segfault.

    public function testIssue88(): void
    {
        $subscription = $this->subscriber->subscribe('foo');
        delay(0.1); // Enter event loop so subscriber has time to connect.
        $subscription->unsubscribe();

        $subscription = $this->subscriber->subscribe('foo');

        async(fn () => $this->redis->publish('foo', 'bar'));

        $this->getNextValue(Pipeline::fromIterable($subscription)->getIterator());

        $receivedValue = $this->getNextValue(Pipeline::fromIterable($subscription)->getIterator());

        $this->assertSame('bar', $receivedValue);
    }

Which results in:

Assertion failed: (p->refcount > 0), function zend_gc_delref, file zend_types.h, line 1342.

Process finished with exit code 134 (interrupted by signal 6:SIGABRT)

PHP Version

8.3.9

Operating System

macOS

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions