Skip to content
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.

Concurrency issue in MsSqlStreamStore.AppendStream #542

Open

Description

@WissemWK

Description:

MsSqlStreamStore.AppendStream's AppendToStreamInternal is not thread-safe when MaxCount has a value. For a high concurrent load relative to a low MaxCount, it may lead to all entries in the Messages table being deleted for the associated Stream, hence all data is lost.

Reproduction steps:

Let's assume that there are 2 messages associated to a stream, with MaxCount = 2, and there are 2 threads calling AppendToStreamInternal simultaneously. Hence, 2 new messages are appended to the stream at the same time. Then, CheckStreamMaxCount is called simultaneously, and the result of GetStreamMessageCount is 2 + 2 = 4 (2 already existing messages, and 2 newly added ones). Thus, the count of messages to be deleted is 2 for each thread. Since each thread tries to remove the 2 oldest messages, regardless, this might leave us with no messages at all, and all messages associated to the stream are lost.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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