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

事件参数被替换,Swoft::trigger('user.login', $uid) #1290

Closed
ctfang opened this issue May 14, 2020 · 6 comments
Closed

事件参数被替换,Swoft::trigger('user.login', $uid) #1290

ctfang opened this issue May 14, 2020 · 6 comments
Assignees
Milestone

Comments

@ctfang
Copy link

ctfang commented May 14, 2020

版本 swoft 2.0.8 swoole 4.4.5

非必现,但是出现后,后面调用一直都报错

调用开始

Swoft::trigger('user.login', $uid)

报错位置

    public function login(EventInterface $event): void
    {
        $uid = $event->getTarget();
        $this->userDao->setOnline($uid);

可以看到,我传入的是int类型参数,$event->getTarget()拿到的是MySqlConnection对象报错信息

app/Listener/UserListener.php(126): App\\Model\\Dao\\UserDao->setOnline(Object(Swoft\\Db\\Connection\\MySqlConnection))
vendor/swoft/stdlib/src/Helper/PhpHelper.php(56): App\\Listener\\UserListener->login(Object(Swoft\\Event\\Event))
vendor/swoft/event/src/Listener/LazyListener.php(50): Swoft\\Stdlib\\Helper\\PhpHelper::call(Array, Object(Swoft\\Event\\Event))
vendor/swoft/event/src/Manager/EventManager.php(736): Swoft\\Event\\Listener\\LazyListener->handle(Object(Swoft\\Event\\Event))
vendor/swoft/event/src/Manager/EventManager.php(331): Swoft\\Event\\Manager\\EventManager->triggerListeners(Object(Swoft\\Event\\Listener\\ListenerQueue), Ob
vendor/swoft/framework/src/Swoft.php(178): Swoft\\Event\\Manager\\EventManager->trigger(Object(Swoft\\Event\\Event), 459, Array)
app/Model/Dao/TokenDao.php(64): Swoft::trigger('user.login', 459)
@github-actions github-actions bot added the swoft: db Issues for swoft db component label May 14, 2020
@ctfang
Copy link
Author

ctfang commented May 14, 2020

出现路径未知,代码不修改,重启后立即正常,很难复现

@ctfang
Copy link
Author

ctfang commented May 14, 2020

image

@inhere inhere added bug bug: waiting fix and removed swoft: db Issues for swoft db component labels May 14, 2020
@inhere inhere added this to the v2.0.10 milestone May 14, 2020
@sakuraovq
Copy link
Member

好的

@inhere inhere added bug: fixed bug fixed and removed bug: waiting fix labels May 15, 2020
@ctfang
Copy link
Author

ctfang commented May 18, 2020

如果能提供复现流程最好,可以避免已有的项目错误

@ctfang
Copy link
Author

ctfang commented May 18, 2020

image

    public function sleep5(EventInterface $event)
    {
        $int = $event->getTarget();

        if ( !is_numeric($int) ){
            throw new \Exception("参数被替换");
        }

        sgo(function (){
            \Swoft::trigger("testInt",10001);
            DB::select("select sleep(1);");
            \Swoft::trigger("testInt",10002);
            \Swoft::trigger("testInt",10003);
        });
        sgo(function (){
            DB::select("select sleep(5);");
        });
        DB::select("select sleep(5);");
        $int = $event->getTarget();

        if ( !is_numeric($int) ){
            throw new \Exception("参数被替换");
        }
        Clog::info("睡眠5秒({$int})");
    }

@Player626
Copy link

class TestListener implements EventHandlerInterface
{
    public function handle(EventInterface $event): void
    {
        var_dump($event->getTarget());
        sgo(function () {

        });
        var_dump($event->getTarget());

    }
}

在里面使用协程就会导致getTarget为空

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

No branches or pull requests

4 participants