From 2621c3695655fa35d7c70a4289cfa5bb4ea06691 Mon Sep 17 00:00:00 2001 From: Miguel Veloso Date: Mon, 17 Jun 2019 22:00:19 +0100 Subject: [PATCH] Add Task.Yield() to avoid synchronus deadlock by ensuring asynchronous execution --- .../EventBus/EventBusRabbitMQ/EventBusRabbitMQ.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/BuildingBlocks/EventBus/EventBusRabbitMQ/EventBusRabbitMQ.cs b/src/BuildingBlocks/EventBus/EventBusRabbitMQ/EventBusRabbitMQ.cs index 99c5b4bbf..5623549d5 100644 --- a/src/BuildingBlocks/EventBus/EventBusRabbitMQ/EventBusRabbitMQ.cs +++ b/src/BuildingBlocks/EventBus/EventBusRabbitMQ/EventBusRabbitMQ.cs @@ -274,6 +274,8 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ var handler = scope.ResolveOptional(subscription.HandlerType) as IDynamicIntegrationEventHandler; if (handler == null) continue; dynamic eventData = JObject.Parse(message); + + await Task.Yield(); await handler.Handle(eventData); } else @@ -283,6 +285,8 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ var eventType = _subsManager.GetEventTypeByName(eventName); var integrationEvent = JsonConvert.DeserializeObject(message, eventType); var concreteType = typeof(IIntegrationEventHandler<>).MakeGenericType(eventType); + + await Task.Yield(); await (Task)concreteType.GetMethod("Handle").Invoke(handler, new object[] { integrationEvent }); } }