Skip to content

Commit b83ea67

Browse files
committed
fix rare race condition
We updated the collection's count before the new value could be retrieved. Between updating the count and actually having something to retrieve was an async call, which allowed the UI thread to retrieve data which was not there.
1 parent f383625 commit b83ea67

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

Signal-Windows/Storage/DB.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,7 @@ public static void SaveMessageLocked(SignalMessage message)
780780

781781
public static List<SignalMessageContainer> GetMessagesLocked(SignalConversation thread, int startIndex, int count)
782782
{
783+
Debug.WriteLine($"GetMessagesLocked {thread.ThreadId} {startIndex} {count}");
783784
lock (DBLock)
784785
{
785786
using (var ctx = new SignalDBContext())

Signal-Windows/ViewModels/MainPageViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,6 @@ public async Task UIHandleIncomingMessage(SignalMessage message)
335335
{
336336
Debug.WriteLine("incoming lock grabbed");
337337
var thread = ThreadsDictionary[message.ThreadId];
338-
thread.MessagesCount += 1;
339338
uint unreadCount = thread.UnreadCount;
340339
if (SelectedThread == thread)
341340
{
@@ -346,6 +345,7 @@ await Task.Run(() =>
346345
SignalDBContext.SaveMessageLocked(message);
347346
});
348347
long? seenId = null;
348+
thread.MessagesCount += 1;
349349
if (SelectedThread == thread)
350350
{
351351
var container = new SignalMessageContainer(message, (int) thread.MessagesCount - 1);

0 commit comments

Comments
 (0)