akkadotnet / Akka.Persistence.MongoDB

MongoDB support for Akka.Persistence
Apache License 2.0
31 stars 36 forks source link

Fix MongoDb operations to use transaction on both read and write #347

Closed Arkatufus closed 1 year ago

Arkatufus commented 1 year ago

Fixes #346 Fixes #345

Changes

Checklist

For significant changes, please ensure that the following have been completed (delete if not relevant):

Latest dev Benchmarks

Include data from the relevant benchmark prior to this change here.

This PR's Benchmarks

Include data from after this change here.

Aaronontheweb commented 1 year ago

@Arkatufus FYI, tests are not running for the majority of the suite

Arkatufus commented 1 year ago

it should be fixed now

Aaronontheweb commented 1 year ago

Akka.Persistence.MongoDb.Tests.MongoDbTransactionCurrentAllEventsSpec.ReadJournal_query_CurrentAllEvents_should_find_existing_events Failed: Timeout 00:00:30 while waiting for a message of type System.String

Gonna see if that fails again upon a re-run

Arkatufus commented 1 year ago

Note for future developers:

As of this PR, the session object used inside a transaction is not thread safe. Never run 2 or more concurrent DB operations inside a transaction, they will cause the transaction to fail horribly. This is easily spotted by looking for any detached Task (any Task that is not await-ed), or the use of Task.WhenAll or Task.WhenAny. Just. Don't.