[BUG反馈]MYSQL长连接中(SWOOLE) 使用事务提交开启断线重连接抛出异常

浏览:1637 发布日期:2020/03/27 分类:ThinkPHP6专区 关键字: BUG TP6 DB长连接 执行事务
官方源代码
vendor/topthink/think-orm/src/db/PDOConnection.php :1369行    public function startTrans(): void
    {
        $this->initConnect(true);

        ++$this->transTimes;

        try {
            if (1 == $this->transTimes) {
                $this->linkID->beginTransaction();
            } elseif ($this->transTimes > 1 && $this->supportSavepoint()) {
                $this->linkID->exec(
                    $this->parseSavepoint('trans' . $this->transTimes)
                );
            }
            $this->reConnectTimes = 0;
        } catch (\Exception $e) {
            if ($this->reConnectTimes < 4 && $this->isBreak($e)) {
                --$this->transTimes;
                ++$this->reConnectTimes;
                $this->close()->startTrans();
            }
            throw $e;
        }
    }
修复建议: 在"throw $e;"上面加个else或 使用return阻止抛出异常    public function startTrans(): void
    {
        $this->initConnect(true);

        ++$this->transTimes;

        try {
            if (1 == $this->transTimes) {
                $this->linkID->beginTransaction();
            } elseif ($this->transTimes > 1 && $this->supportSavepoint()) {
                $this->linkID->exec(
                    $this->parseSavepoint('trans' . $this->transTimes)
                );
            }
            $this->reConnectTimes = 0;
        } catch (\Exception $e) {
            if ($this->reConnectTimes < 4 && $this->isBreak($e)) {
                --$this->transTimes;
                ++$this->reConnectTimes;
                $this->close()->startTrans();
            }else{
                throw $e;
            }
        }
    }
最佳答案
评论( 相关
后面还有条评论,点击查看>>