详情页

onWorkerStart时添加定时任务会导致register验证出错 Register auth timeout

时间:2023年05月10日

编辑:佚名

GatewayWorker businessworker中 onWorkerStart时添加一个一小时以上的定时任务会导致register验证出错 报 pid:1 Register auth timeout (127.0.0.1). See http://wiki.workerman.net/Error4 for detail 错误,
查找原因为BusinessWorker 类中的connectToRegister方法$this->_registerConnection->send('{"event":"worker_connect","secret_key":"' . $this->secretKey . '"}'); 没有发送消息成功,
猜想原因:发送语句不是链接成功后执行的,而添加的大于一小时的定时任务阻塞了_registerConnection链接()。
解决办法将$this->_registerConnection->send('{"event":"worker_connect","secret_key":"' . $this->secretKey . '"}');
改为:
$this->_registerConnection->onConnect = function()
    {
        $this->_registerConnection->send('{"event":"worker_connect","secret_key":"' . $this->secretKey . '"}');
    };
workerman爱好者:walkor
你的GatewayWorker版本应该不是最新的,最新的版本Gateway与businessworker的验证是在onConnect中完成的,最新版本支持了多register,使得GatewayWorker具有超高可用性。
最后不建议将耗时任务放在businessworker中,这样会进程阻塞,Gateway转发给businessworker的任务无法及时处理,导致消息处理或发送延迟。
相关文章
猜你需要