-
Notifications
You must be signed in to change notification settings - Fork 324
Open
Labels
bugSomething isn't workingSomething isn't working
Description
✅ 验证清单
- 🔍 我已经搜索过 现有 Issues,确信这不是重复问题
🚀 Go 版本
go 1.20
📦 Seata-go 版本
v1.2.1
💾 操作系统
🪟 Windows
📝 Bug 描述
XA Mode Transaction Failures: 'busy buffer' and 'bad connection' Errors Causing Rollbacks with FOR UPDATE Queries
在使用那个 xa 模式下,sql 先去查询(加FOR UPDATE),然后去更新数据,
然后那个deriver一直报 busy buffer 和 deriver bad connection 错误,导致事务一直回滚
func (a *AccountService) Deduct(ctx context.Context, account model.Account) error {
var userAccount model.Account
err := a.db.WithContext(ctx).Where("user_id = ?", account.UserID).First(&userAccount).Error
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return fmt.Errorf("account not found for user_id: %d", account.UserID)
}
return fmt.Errorf("failed to query account: %w", err)
}
if userAccount.Balance < account.Balance {
return fmt.Errorf("insufficient balance: current balance %d, required %d", userAccount.Balance, account.Balance)
}
// 计算扣减后的新余额
newBalance := userAccount.Balance - account.Balance
err = a.db.WithContext(ctx).Model(&model.Account{}).
Where("user_id = ?", account.UserID).
Update("balance", newBalance).Error
if err != nil {
return fmt.Errorf("failed to deduct balance: %w", err)
}
return nil
}这个问题好像是一个重复的问题,之前那个 ISSUE 好像没有解决但是 closed 了
#554
🔄 重现步骤
https://github.com/yumosx/samples/tree/main/quick_start
- 进入对应的 cmd 目录下面, 分别启动 对应的 grpc服务 和 gin 服务
- 请求对应的接口
curl --location 'http://localhost:8080/order/create' \
--header 'Content-Type: application/json' \
--data '{
"user_id": "1",
"count": 2,
"money" : 8
}'
✅ 预期行为
预期应该是可以执行成功的, 没有 driver bad connection 错误,
❌ 实际行为
driver bad connection 错误,
💡 可能的解决方案
No response
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working