go
runtime_error
ai_generated
true
sql:事务已提交或回滚
sql: transaction has already been committed or rolled back
ID: go/database-sql-tx-committed
80%修复率
88%置信度
0证据数
2024-07-12首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.21 | active | — | — | — |
根因分析
在已提交或回滚的事务上执行查询。
English
Attempting to execute a query on a transaction that has already been committed or rolled back.
解决方案
-
90% 成功率
tx, err := db.BeginTx(ctx, nil) if err != nil { // handle } // defer tx.Rollback() to ensure cleanup if err := tx.Commit(); err != nil { // handle } -
70% 成功率
Check the transaction state before executing queries.
无效尝试
常见但无效的做法:
-
90% 失败
Once a transaction is done, it cannot be reused.
-
80% 失败
Commit() can only be called once.