Transactions: rollback errors when commit failed because of WrongExpectedVersion

I’m working with 3.0.0

I’ve got a generic SaveEvents method that opens a transaction, writes EventData objects to it, and then tries to commit it but will rollback if it fails. The problem I’m having is that the rollback itself fails if the commit errors because of a WrongExpectedVersion. The error thrown in rollback is that the transaction is already committed, which I would not have expected.

Just curious if this is a bug, or if it’s intended and I should be handling it?

Thanks

Can you write up a quick example just so I’m clear on the behavior being discussed?

Sure, I’ll keep it simple for the sake of brevity but I can be more descriptive if you need me to

So basically I make a connection, create a transaction, write EventData to it, and then I do this:

try     return! transaction.CommitAsync() |> Async.AwaitTask with ex ->                     transaction.Rollback()     return raise ex

I’ve made a unit test to create a fail case, I decided to use a WrongExpectedVersion exception since it was easy to do



// Act let newStream = String.Format(“EventStoreTest_{0}”, Guid.NewGuid().ToString()) // Assert // Expected Version should be -1 for a new stream, 0 will throw an error Assert.Throws(fun () -> EventStore.SaveEvents newStream 0 testEvents |> ignore)

``


This test errors because an InvalidOperationException is what gets thrown, what happens when I debug is I get to the catch, but then I get a failure in the transaction.Rollback() call, and the exception I get is "System.InvalidOperationException: Transaction is already committed"

Sorry the formatting didn’t work like I expected

try
    return! transaction.CommitAsync() |> Async.AwaitTask
with ex ->                
    transaction.Rollback()
    return raise ex


// Act
let newStream = String.Format(“EventStoreTest_{0}”, Guid.NewGuid().ToString())

// Assert
// Expected Version should be -1 for a new stream, 0 will throw an error
Assert.Throws(fun () -> EventStore.SaveEvents newStream 0 testEvents |> ignore)