Skip to content

Commit

Permalink
Fix rollback
Browse files Browse the repository at this point in the history
  • Loading branch information
fbiville committed May 17, 2023
1 parent 8c1268b commit b74567b
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions neo4j/transaction_with_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,12 @@ func (tx *explicitTransaction) Run(ctx context.Context, cypher string, params ma
}

func (tx *explicitTransaction) Commit(ctx context.Context) error {
if err := tx.checkCompleted(); err != nil {
return err
if tx.runFailed {
tx.runFailed = false
return tx.err
}
if tx.conn == nil {
return transactionAlreadyCompletedError()
}
tx.err = tx.conn.TxCommit(ctx, tx.txHandle)
tx.onClosed(tx)
Expand All @@ -97,8 +101,12 @@ func (tx *explicitTransaction) Close(ctx context.Context) error {
}

func (tx *explicitTransaction) Rollback(ctx context.Context) error {
if err := tx.checkCompleted(); err != nil {
return err
if tx.runFailed {
tx.runFailed = false
return nil
}
if tx.conn == nil {
return transactionAlreadyCompletedError()
}
if !tx.conn.IsAlive() || tx.conn.HasFailed() {
// tx implicitly rolled back by having failed
Expand All @@ -110,17 +118,6 @@ func (tx *explicitTransaction) Rollback(ctx context.Context) error {
return errorutil.WrapError(tx.err)
}

func (tx *explicitTransaction) checkCompleted() error {
if tx.runFailed {
tx.runFailed = false
return tx.err
}
if tx.conn == nil {
return transactionAlreadyCompletedError()
}
return nil
}

func (tx *explicitTransaction) legacy() Transaction {
return &transaction{
delegate: tx,
Expand Down

0 comments on commit b74567b

Please sign in to comment.