You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Commit commits the transaction.func (tx*Tx) Commit() error {
// Check context first to avoid transaction leak.// If put it behind tx.done CompareAndSwap statement, we can't ensure// the consistency between tx.done and the real COMMIT operation.select {
default:
case<-tx.ctx.Done():
ifatomic.LoadInt32(&tx.done) ==1 {
returnErrTxDone
}
returntx.ctx.Err()
}
if!atomic.CompareAndSwapInt32(&tx.done, 0, 1) {
returnErrTxDone
}
// Cancel the Tx to release any active R-closemu locks.// This is safe to do because tx.done has already transitioned// from 0 to 1. Hold the W-closemu lock prior to rollback// to ensure no other connection has an active query.tx.cancel()
tx.closemu.Lock()
tx.closemu.Unlock()
varerrerrorwithLock(tx.dc, func() {
err=tx.txi.Commit()
})
if!errors.Is(err, driver.ErrBadConn) {
tx.closePrepared()
}
tx.close(err)
returnerr
}
What did you expect to see?
what is the use of the lock? unlock immediately after lock.
What did you see instead?
Is it possible to delete the lock code?
tx.closemu.Lock()
tx.closemu.Unlock()
The text was updated successfully, but these errors were encountered:
Because we only want to ensure there is no active query, and the tx is already marked as done, so no new queries can start. so just locking and unlocking (W) should be sufficent.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Please see this code:
What did you expect to see?
what is the use of the lock? unlock immediately after lock.
What did you see instead?
Is it possible to delete the lock code?
The text was updated successfully, but these errors were encountered: