From 2d2017bd84d7736b5007cd1d379c0a4ed707f5ea Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Wed, 8 Apr 2026 09:14:15 +0200 Subject: [PATCH] Fix race condition in EventConsumerProcessor.CompleteAsync causing flaky test (#1306) * Fix race condition in EventConsumerProcessor.CompleteAsync Agent-Logs-Url: https://github.com/Squidex/squidex/sessions/b55e1925-e661-469b-99cb-bcf3c6ff5cfd Co-authored-by: SebastianStehle <1236435+SebastianStehle@users.noreply.github.com> * Replace empty using block with idiomatic using-var discard Agent-Logs-Url: https://github.com/Squidex/squidex/sessions/6bb99aa7-f129-4ec3-939b-43b41cb22b31 Co-authored-by: SebastianStehle <1236435+SebastianStehle@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: SebastianStehle <1236435+SebastianStehle@users.noreply.github.com> --- .../EventSourcing/Consume/EventConsumerProcessor.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/backend/src/Squidex.Infrastructure/EventSourcing/Consume/EventConsumerProcessor.cs b/backend/src/Squidex.Infrastructure/EventSourcing/Consume/EventConsumerProcessor.cs index 9202f962e..2417afeb3 100644 --- a/backend/src/Squidex.Infrastructure/EventSourcing/Consume/EventConsumerProcessor.cs +++ b/backend/src/Squidex.Infrastructure/EventSourcing/Consume/EventConsumerProcessor.cs @@ -72,6 +72,9 @@ public class EventConsumerProcessor : IEventSubscriber log.LogCritical(ex, "Failed to complete consumer."); } } + + // Acquire the lock to ensure any in-flight UpdateAsync has fully completed before returning. + using var _ = await asyncLock.EnterAsync(); } public virtual ValueTask OnNextAsync(IEventSubscription subscription, ParsedEvents @event)