From d7dd915d767150d61402ac67becc6c5599988a58 Mon Sep 17 00:00:00 2001 From: maliming Date: Tue, 19 Aug 2025 14:22:32 +0800 Subject: [PATCH] Add error handling to InboxProcessor event processing Wrapped event processing in a try-catch block to log errors when processing individual events fails. This prevents one failed event from interrupting the processing of subsequent events and improves reliability. --- .../EventBus/Distributed/InboxProcessor.cs | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/InboxProcessor.cs b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/InboxProcessor.cs index 06014701a2..f0d86627ae 100644 --- a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/InboxProcessor.cs +++ b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/InboxProcessor.cs @@ -103,18 +103,25 @@ public class InboxProcessor : IInboxProcessor, ITransientDependency foreach (var waitingEvent in waitingEvents) { - using (var uow = UnitOfWorkManager.Begin(isTransactional: true, requiresNew: true)) + try { - await DistributedEventBus - .AsSupportsEventBoxes() - .ProcessFromInboxAsync(waitingEvent, InboxConfig); + using (var uow = UnitOfWorkManager.Begin(isTransactional: true, requiresNew: true)) + { + await DistributedEventBus + .AsSupportsEventBoxes() + .ProcessFromInboxAsync(waitingEvent, InboxConfig); - await Inbox.MarkAsProcessedAsync(waitingEvent.Id); + await Inbox.MarkAsProcessedAsync(waitingEvent.Id); - await uow.CompleteAsync(StoppingToken); - } + await uow.CompleteAsync(StoppingToken); + } - Logger.LogInformation($"Processed the incoming event with id = {waitingEvent.Id:N}"); + Logger.LogInformation($"Processed the incoming event with id = {waitingEvent.Id:N}"); + } + catch (Exception e) + { + Logger.LogError(e, $"An error occurred while processing the incoming event with id = {waitingEvent.Id:N}"); + } } } }