swoft-cloud / swoft

🚀 PHP Microservice Full Coroutine Framework
https://swoft.org
Apache License 2.0
5.58k stars 786 forks source link

After PipeMessage event, the data produced by the coroutine is not destroyed #1408

Closed anhoder closed 3 years ago

anhoder commented 3 years ago
Q A
Bug report? yes
Feature request? no
Swoft version 2.0.10
Swoole version 4.5.10
PHP version 7.3.23
Runtime environment Mac

Describe the bug After PipeMessage event, the data produced by the coroutine is not destroyed. And it will cause a memory leak.

My Code


// ==== TaskPipeMessageListener.php ====
/**
 * Class TaskPipeMessageListener
 * @package App\Listener
 *
 * @Listener(ServerEvent::PIPE_MESSAGE)
 */
class PipeMessageListener implements EventHandlerInterface
{
    /**
     * @inheritDoc
     */
    public function handle(EventInterface $event): void
    {
        var_dump(memory_get_usage());

        Plan::orderByDesc('planid')->first();
        Redis::expire('test', 10);
    }
}

// ==== CronTask.php ====
/**
 * Class CronTask
 *
 * @since 2.0
 *
 * @Scheduled()
 */
class CronTask
{

    /**
     * @Cron("* * * * * *")
     *
     * @throws Exception
     */
    public function secondTask(): void
    {
        $server = server()->getSwooleServer();

        $server->sendMessage('', 0);
    }

}

Screenshots

int(26134800)
int(26278528)
int(26340392)
int(26402256)
int(26464120)
int(26525984)
int(26578872)
int(26633040)
int(26685928)
int(26738816)
int(26791704)
int(26796336)
int(26800968)
int(26805600)
int(26810232)
int(26817424)
...
int(28371832)
int(28376464)
int(28381096)
int(28385728)
int(28390360)
int(28394992)
issue-label-bot[bot] commented 3 years ago

Issue-Label Bot is automatically applying the label bug to this issue, with a confidence of 0.91. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback!

Links: app homepage, dashboard and code for this bot.