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

在PDOConnection.php的startTrans()方法中,官方源代码在处理MySQL长连接和事务时,如果断线会尝试重连。但在重连失败后会抛出异常。修复建议是在异常处理部分增加一个else分支,避免异常直接被抛出,从而提供更稳定的事务处理。
摘要由CSDN通过智能技术生成

官方源代码

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 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 isBreak($e)) {

--$this->transTimes;

++$this->reConnectTimes;

$this->close()->startTrans();

}else{

throw $e;

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值