Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fiber stack variables do not participate in cycle collector #9735

Closed
xjaja opened this issue Oct 12, 2022 · 4 comments
Closed

Fiber stack variables do not participate in cycle collector #9735

xjaja opened this issue Oct 12, 2022 · 4 comments

Comments

@xjaja
Copy link

xjaja commented Oct 12, 2022

Description

behavior1: 3v4l
behavior2: 3v4l

The following code:

<?php
class ClassName1
{
    function __destruct() {
        print "Destroying " . __CLASS__ . "\n";
    }
}

$fiber = new Fiber(
    function() {
        $d1 = new ClassName1;

        // Resulted output
        $d2 = \WeakReference::create(\Fiber::getCurrent())->get();
        
        // Expected output
        //\WeakReference::create(\Fiber::getCurrent())->get();

        Fiber::suspend();
        return ;
    }
);
echo "1\n";
$fiber->start();

echo "2\n";
$fiber = null;

echo "3\n";

Resulted in this output:

1
2
3
Destroying ClassName1

But I expected this output instead:

1
2
Destroying ClassName1
3

PHP Version

php 8.1.11

Operating System

No response

@bwoebi
Copy link
Member

bwoebi commented Oct 13, 2022

It's not related to WeakReferences though: just writing $d2 = \Fiber::getCurrent(); exposes the same behaviour.

The problem is that assigning the current Fiber to a variable causes a cycle, but stack variables of fibers are not participating in the cycle collection (zend_fiber_object_gc is not adding these).

@bwoebi bwoebi changed the title Problem in WeakReference Fiber stack variables do not participate in cycle collector Oct 13, 2022
@arnaud-lb arnaud-lb self-assigned this Oct 14, 2022
@arnaud-lb
Copy link
Member

Fixed in #9810

Thanks!

@andypost
Copy link
Contributor

andypost commented Jan 21, 2023

Used to build PHP 8.2.2RC1 and got all added tests to fail on x86 32-bits https://gitlab.alpinelinux.org/alpine/aports/-/jobs/954955

TEST 2578/15917 [Zend/tests/fibers/gh9735-001.phpt]
========DIFF========
     1
�[1;31m002- 2�[0m
�[1;31m003- C::__destruct�[0m
�[1;31m004- 3�[0m
========DONE========
�[1;31mFAIL�[0m Bug GH-9735 001 (Fiber stack variables do not participate in cycle collector) [Zend/tests/fibers/gh9735-001.phpt] 
TEST 2579/15917 [Zend/tests/fibers/gh9735-002.phpt]
========DIFF========
     1
�[1;31m002- 2�[0m
�[1;31m003- C::__destruct�[0m
�[1;31m004- 3�[0m
========DONE========
�[1;31mFAIL�[0m Bug GH-9735 002 (Fiber stack variables do not participate in cycle collector) [Zend/tests/fibers/gh9735-002.phpt] 
TEST 2580/15917 [Zend/tests/fibers/gh9735-003.phpt]
========DIFF========
     1
�[1;31m002- 2�[0m
�[1;31m003- C::__destruct�[0m
�[1;31m004- 3�[0m
========DONE========
�[1;31mFAIL�[0m Bug GH-9735 003 (Fiber stack variables do not participate in cycle collector) [Zend/tests/fibers/gh9735-003.phpt] 
TEST 2581/15917 [Zend/tests/fibers/gh9735-004.phpt]
========DIFF========
     1
�[1;31m002- 2�[0m
�[1;31m003- C::__destruct�[0m
�[1;31m004- 3�[0m
========DONE========
�[1;31mFAIL�[0m Bug GH-9735 004 (Fiber stack variables do not participate in cycle collector) [Zend/tests/fibers/gh9735-004.phpt] 
TEST 2582/15917 [Zend/tests/fibers/gh9735-005.phpt]
========DIFF========
     1
�[1;31m002- 2�[0m
�[1;31m003- C::__destruct�[0m
�[1;31m004- 3�[0m
========DONE========
�[1;31mFAIL�[0m Bug GH-9735 005 (Fiber stack variables do not participate in cycle collector) [Zend/tests/fibers/gh9735-005.phpt] 
TEST 2583/15917 [Zend/tests/fibers/gh9735-006.phpt]
========DIFF========
     1
�[1;31m002- 2�[0m
�[1;31m003- C::__destruct�[0m
�[1;31m004- 3�[0m
========DONE========
�[1;31mFAIL�[0m Bug GH-9735 006 (Fiber stack variables do not participate in cycle collector) [Zend/tests/fibers/gh9735-006.phpt] 
TEST 2584/15917 [Zend/tests/fibers/gh9735-007.phpt]
========DIFF========
     1
�[1;31m002- 2�[0m
�[1;31m003- C::__destruct�[0m
�[1;31m004- 3�[0m
========DONE========
�[1;31mFAIL�[0m Bug GH-9735 007 (Fiber stack variables do not participate in cycle collector) [Zend/tests/fibers/gh9735-007.phpt] 
TEST 2585/15917 [Zend/tests/fibers/gh9735-008.phpt]
========DIFF========
     1
�[1;31m002- 2�[0m
�[1;31m003- C::__destruct�[0m
�[1;31m004- 3�[0m
========DONE========
�[1;31mFAIL�[0m Bug GH-9735 008 (Fiber stack variables do not participate in cycle collector) [Zend/tests/fibers/gh9735-008.phpt] 
TEST 2586/15917 [Zend/tests/fibers/gh9735-009.phpt]
========DIFF========
     1
�[1;31m002- 2�[0m
�[1;31m003- C::__destruct�[0m
�[1;31m004- 3�[0m
========DONE========
�[1;31mFAIL�[0m Bug GH-9735 009 (Fiber stack variables do not participate in cycle collector) [Zend/tests/fibers/gh9735-009.phpt] 

@arnaud-lb
Copy link
Member

@andypost aports/community/php82 has a long list of ignored tests for x86 here: https://gitlab.alpinelinux.org/alpine/aports/-/blob/aee689a7757d8d3550b85a001d9c00543f71569e/community/php82/disabled-tests.x86.list. The list includes most Fibers tests, but not the new ones added by #9810.

There seems to be a more generate issue with fibers on alpine/x86/clang. I've created a separate issue: #10398

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants