[php-src] Issue #15108: Segfault / Assertion failed: (p->refcount > 0), function zend_gc_delref, file zend_types.h, line 1342
| From: | kelunik | Date: | Thu, 25 Jul 2024 21:30:03 +0000 |
| Subject: | [php-src] Issue #15108: Segfault / Assertion failed: (p->refcount > 0), function zend_gc_delref, file zend_types.h, line 1342 | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-247376@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/15108
Author: kelunik
### Description
The following code:
```php
#!/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());
```
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.
```php
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