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

fix: all coroutines must be canceled before Event::exit #1059

Merged
merged 1 commit into from
Oct 2, 2024

Conversation

chaz6chez
Copy link
Contributor

@chaz6chez chaz6chez commented Oct 1, 2024

在webman的协程基建插件( https://www.workerman.net/plugin/167 )的测试中发现,使用channel、waitGroup组件或者被hook的系统函数如sleep进行处理业务时,在退出workerman时会发生[FATAL ERROR]: all coroutines (count: N) are asleep - deadlock!(其中的N是退出时的协程数量)等错误;
可能的错误还有:

  • WARNING Channel::~Channel() (ERRNO 10003): channel is destroyed, 1 consumers will be discarded
  • Fatal error: Uncaught Swoole\Error: API must be called in the coroutine in @swoole/library/core/Coroutine/WaitGroup.php

webman协程基建插件后续对于swow、swoole事件的测试反馈会持续跟进提交到workerman。

另外,协程基建目前做的不仅针对于webman的协程化,还提供了workerman的worker/server的协程化。

@walkor walkor merged commit 8e1dfd8 into walkor:master Oct 2, 2024
18 checks passed
@walkor
Copy link
Owner

walkor commented Oct 2, 2024

非常感谢,这个问题困扰很久了。

@chaz6chez
Copy link
Contributor Author

因为不是很清楚posix_kill(posix_getpid(), SIGINT);的含义,所以没有动,我自己的驱动实现实际上没有用到这行代码:

/** @inheritdoc  */
    public function loop()
    {
        // 阻塞等待
        Event::wait();
        // 确定loop为退出状态
        exit(0);
    }

    /** @inheritdoc  */
    public function destroy()
    {
        // 移除所有定时器
        $this->clearAllTimer();
        // 退出所有协程
        foreach (Coroutine::listCoroutines() as $coroutine) {
            Coroutine::cancel($coroutine);
        }
        // 退出event loop
        Event::exit();
        $this->_reads = $this->_writes = [];
    }

@walkor
Copy link
Owner

walkor commented Oct 2, 2024 via email

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

Successfully merging this pull request may close these issues.

2 participants