Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,10 @@ protected async Task Flush()
_timeout = null;
}

var i = 0;

Queue<TypingActivity> informativeUpdates = new();
var startCount = _queue.Count;
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ConcurrentQueue<T>.Count can be O(n) and is an imprecise snapshot under concurrency. Since this value is only used to decide whether to return, it’s more efficient and accurate to avoid Count entirely and instead track a local dequeued counter (or a boolean flag) while draining.

Copilot uses AI. Check for mistakes.

while (i <= 10 && _queue.TryDequeue(out var activity))
while (_queue.TryDequeue(out var activity))
{
if (activity is MessageActivity message)
{
Expand All @@ -159,11 +158,10 @@ protected async Task Flush()
informativeUpdates.Enqueue(typing);
}

i++;
_count++;
}

if (i == 0) return;
if (startCount == 0) return;
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

startCount is computed from _queue.Count, which is not a reliable indicator of whether this flush actually dequeued items in concurrent scenarios. If _queue.Count is 0 at line 138 but items are enqueued immediately after and then dequeued in the loop, startCount == 0 will still be true and the method will return early, potentially dropping/defering sends even though activities were drained and _count was incremented. Prefer tracking whether anything was actually dequeued (e.g., var dequeued = 0; increment inside the loop and if (dequeued == 0) return;), which matches the previous i == 0 behavior and avoids reliance on _queue.Count.

Copilot uses AI. Check for mistakes.

// Send informative updates
if (informativeUpdates.Count > 0)
Expand Down
Loading