Skip to content

Fiber stack variables do not participate in cycle collector #9735

Closed

Description

@xjaja

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

Activity

  1. bwoebi commented on Oct 13, 2022

    @bwoebi
    Member

    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).

  2. changed the title [-]Problem in WeakReference[/-] [+]Fiber stack variables do not participate in cycle collector[/+] on Oct 13, 2022
  3. self-assigned this
    on Oct 14, 2022
  4. arnaud-lb commented on Jan 13, 2023

    @arnaud-lb
    Member

    Fixed in #9810

    Thanks!

  5. andypost commented on Jan 21, 2023

    @andypost
    Contributor

    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] 
    
  6. arnaud-lb commented on Jan 21, 2023

    @arnaud-lb
    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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions