swoole / library

📚 Swoole Library
https://wiki.swoole.com/#/library
Apache License 2.0
233 stars 59 forks source link

fix Coroutine\Barrier mem leak #94

Closed Appla closed 3 years ago

Appla commented 3 years ago

the static property $cancel_list hold the value set in destruct in some case. after barrier object destructed by set it's reference by null, we can unset this that value added in destruct

the following test case could trigger this issue

    /**
     * Test without execution switching between coroutines.
     *
     * @covers \Swoole\Coroutine\Barrier
     */
    public function testNoCoroutineSwitching()
    {
        run(function () {
            $barrier = Barrier::make();
            $count = 0;
            $N = 4;
            foreach (range(1, $N) as $i) {
                \Swoole\Coroutine::create(function () use ($barrier, &$count) {
                    $count++;
                });
            }
            Barrier::wait($barrier);

            $this->assertSame($N, $count, 'The parent coroutine keeps running without switching execution to child coroutines.');
        });
    }
deminy commented 3 years ago

Linking to a similar PR (#69) submitted by @sy-records .