EventFlow icon indicating copy to clipboard operation
EventFlow copied to clipboard

PopulateAsync gets stuck in while loop if any of the event upgraders throw an exception

Open baltuonis opened this issue 10 months ago • 4 comments

Here is the code that I'm using to run IReadModelPopulator

var typeList = typeof(DependencyInjection).Assembly.DefinedTypes
            .Where(type => !type.IsInterface && !type.IsAbstract && 
                           type.ImplementedInterfaces.Any(inter => inter == typeof(IReadModel))).ToList();
foreach (var x in typeList)
{
    await populator.PurgeAsync(x, ct);
}
await populator.PopulateAsync(typeList, ct);

It happens that if any of the event upgraders throw an exception will get stuck ReadModelPopulator in a while loop waiting for more events to be enqueued to _pipedEvents.

When an exception occurs it will fail on ReadModelPopulator:144, meanwhile a ReadModelPopulator:173 while loop will run for an eternity.

What's worse I was not seeing any errors in the Logging, so it took me a while to figure it out (maybe my logging levels are wrong)

I assume that event upgraders should never ever throw any exceptions (it should just skip the event and log an error, right?)

Suggestions for a fix:

  1. Make sure it catches and logs exceptions
  2. Make sure ProcessEventQueue won't run infinitely

baltuonis avatar Feb 20 '25 00:02 baltuonis

I verified that the read model populator indeed doesn't stop if there's an exception and fixed it by parsing the cancellation token. However I'm currently stuck in ensuring that the exception is throw when it occurs. Right now its only thrown when the cancellation happens.

See #1087

rasmus avatar Mar 09 '25 14:03 rasmus

Thanks a lot. That was fast. Do you have an approximate date of the next release that will include this fix?

Btw - we love this library

baltuonis avatar Mar 13 '25 15:03 baltuonis

I'll get this merged and release this weekend

rasmus avatar May 29 '25 08:05 rasmus

Awesome thanks

baltuonis avatar May 29 '25 17:05 baltuonis

Forgot to close this after releasing the fix

rasmus avatar Oct 11 '25 11:10 rasmus

Thank you!

baltuonis avatar Oct 11 '25 16:10 baltuonis