You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 15, 2024. It is now read-only.
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.