Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Aug 15, 2024. It is now read-only.
This repository was archived by the owner on Aug 15, 2024. It is now read-only.

Concurrent appends to same stream and ExpectedVersion.Any on Postgres throws WrongExpectedVersion #478

Copy link
Copy link
@stoft

Description

@stoft
Issue body actions

We tried to concurrently append to the same stream with ExpectedVersion.Any (commutative events), using Postgres as underlying DB, and it fails throwing WrongExpectedVersion. We've tried both using a single connection and with dedicated connections but with the same result.

For comparison I tried doing the same with MySQL which deadlocked on a single connection but passed on dedicated connections. I may give SQL Server a whirl tomorrow. The In Memory Store works fine.

SSS version: 1.2.0-beta.8 (latest published version of SSS.Postgres on nuget)
Postgres: 9.6 (local docker) & 12.3 (AWS RDS)

The example test case below uses dedicated connections (F# with Expecto, if needed I could probably convert it to C# within a few days):

ftest "repro concurrency error" {
    let streamStore () =
        let settings =
            SqlStreamStore.PostgresStreamStoreSettings
                ("Host=localhost;Port=5432;User Id=user;Password=password;Database=db")

        settings.Schema <- "teststreamstore"

        new SqlStreamStore.PostgresStreamStore(settings)

    let appendMsg msg =
        try
            (streamStore ())
                .AppendToStream(SqlStreamStore.Streams.StreamId
                                    ("test"),
                                SqlStreamStore.Streams.ExpectedVersion.Any,
                                [| msg |])
            |> Async.AwaitTask
            with exn ->
                failtest ("should not fail: " + exn.Message)

    let message () =
        SqlStreamStore.Streams.NewStreamMessage
            (System.Guid.NewGuid (), "some-type", "{}", "{}")

    List.map (fun _ -> appendMsg (message ())) [ 0 .. 10 ]
    |> List.map Async.RunSynchronously
};
Error Message:
   Append failed due to WrongExpectedVersion.Stream: test, Expected version: -2
  Stack Trace:
     at SqlStreamStore.PostgresStreamStore.AppendToStreamInternal(String streamId, Int32 expectedVersion, NewStreamMessage[] messages, CancellationToken cancellationToken)
Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.