Skip to content

Commit

Permalink
Merge pull request #1049 from aksio-insurtech:fix/execution-context
Browse files Browse the repository at this point in the history
Ensuring execution context is correct
  • Loading branch information
einari authored Dec 12, 2023
2 parents b66491a + b4ad1b5 commit 4fccb00
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Source/Kernel/Grains/EventSequences/EventSequences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,20 @@ namespace Aksio.Cratis.Kernel.Grains.EventSequences;
/// </summary>
public class EventSequences : Grain, IEventSequences
{
readonly IExecutionContextManager _executionContextManager;
readonly ILogger<EventSequences> _logger;
EventSequencesKey _key = EventSequencesKey.NotSet;

/// <summary>
/// Initializes a new instance of the <see cref="EventSequences"/> class.
/// </summary>
/// <param name="executionContextManager"><see cref="IExecutionContextManager"/> for managing the execution context.</param>
/// <param name="logger">Logger for logging.</param>
public EventSequences(ILogger<EventSequences> logger)
public EventSequences(
IExecutionContextManager executionContextManager,
ILogger<EventSequences> logger)
{
_executionContextManager = executionContextManager;
_logger = logger;
}

Expand Down Expand Up @@ -49,6 +54,7 @@ public async Task Rehydrate()
var grain = GrainFactory.GetGrain<IEventSequence>(eventSequence, eventSequenceKey);
try
{
_executionContextManager.Establish(_key.TenantId, CorrelationId.New(), _key.MicroserviceId);
await grain.Rehydrate();
}
catch (Exception ex)
Expand Down
2 changes: 2 additions & 0 deletions Source/Kernel/Server/BootProcedure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ await schemaStore.Register(

foreach (var (tenantId, _) in _configuration.Tenants)
{
_executionContextManager.Establish(tenantId, CorrelationId.New(), microserviceId);

foreach (var outbox in microservice.Inbox.FromOutboxes)
{
var key = new InboxKey(tenantId, outbox.Microservice);
Expand Down
49 changes: 49 additions & 0 deletions Source/Kernel/Server/log.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
Autofac.Core.DependencyResolutionException: An exception was thrown while activating Aksio.Cratis.Kernel.Engines.Compliance.JsonComplianceManager.\n
---> Autofac.Core.DependencyResolutionException: An exception was thrown while invoking the constructor 'Void .ctor(Aksio.Types.IInstancesOf`1[Aksio.Cratis.Kernel.Engines.Compliance.IJsonCompliancePropertyValueHandler])' on type 'JsonComplianceManager'.\n
---> Autofac.Core.DependencyResolutionException: An exception was thrown while activating Aksio.Cratis.Kernel.Engines.Compliance.GDPR.PIICompliancePropertyValueHandler.\n
---> Aksio.Execution.ExecutionContextNotSet: Execution context is not set\n
at Aksio.Execution.ExecutionContextManager.GetCurrent()\n
at Aksio.Applications.Autofac.SingletonPerMicroserviceComponentLifetime.FindScope(ISharingLifetimeScope mostNestedVisibleScope)\n
at Autofac.Core.Resolving.Middleware.ScopeSelectionMiddleware.Execute(ResolveRequestContext context, Action`1 next)\n at Autofac.Core.Resolving.Middleware.CircularDependencyDetectorMiddleware.Execute(ResolveRequestContext context, Action`1 next)\n
at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, ResolveRequest request)\n
at Autofac.Core.Activators.Reflection.BoundConstructor.Instantiate()\n
at Autofac.Core.Activators.Reflection.ReflectionActivator.<>c__DisplayClass12_0.<UseSingleConstructorActivation>b__0(ResolveRequestContext ctxt, Action`1 next)\n
at Autofac.Core.Resolving.Middleware.DisposalTrackingMiddleware.Execute(ResolveRequestContext context, Action`1 next)\n
at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action`1 next)\n

--- End of inner exception stack trace ---\n
at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action`1 next)\n
at Autofac.Core.Resolving.Middleware.SharingMiddleware.Execute(ResolveRequestContext context, Action`1 next)\n
at Autofac.Core.Resolving.Middleware.CircularDependencyDetectorMiddleware.Execute(ResolveRequestContext context, Action`1 next)\n
at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, ResolveRequest request)\n
at Autofac.Core.Resolving.ResolveOperation.ExecuteOperation(ResolveRequest request)\n
at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable`1 parameters, Object& instance)\n
at Autofac.ResolutionExtensions.ResolveOptionalService(IComponentContext context, Service service, IEnumerable`1 parameters)\n
at Aksio.Types.InstancesOf`1.GetEnumerator()+MoveNext()\n
at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)\n
at Aksio.Cratis.Kernel.Engines.Compliance.JsonComplianceManager..ctor(IInstancesOf`1 propertyValueHandlers)\n
at lambda_method21(Closure, Object[])\n
at Autofac.Core.Activators.Reflection.BoundConstructor.Instantiate()\n

--- End of inner exception stack trace ---\n
at Autofac.Core.Activators.Reflection.BoundConstructor.Instantiate()\n
at Autofac.Core.Activators.Reflection.ReflectionActivator.<>c__DisplayClass12_0.<UseSingleConstructorActivation>b__0(ResolveRequestContext ctxt, Action`1 next)\n
at Autofac.Core.Resolving.Middleware.DisposalTrackingMiddleware.Execute(ResolveRequestContext context, Action`1 next)\n
at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action`1 next)\n

--- End of inner exception stack trace ---\n
at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action`1 next)\n
at Autofac.Core.Resolving.Middleware.SharingMiddleware.<>c__DisplayClass5_0.<Execute>b__0()\n
at Autofac.Core.Lifetime.LifetimeScope.CreateSharedInstance(Guid id, Func`1 creator)\n
at Autofac.Core.Lifetime.LifetimeScope.CreateSharedInstance(Guid primaryId, Nullable`1 qualifyingId, Func`1 creator)\n
at Autofac.Core.Resolving.Middleware.SharingMiddleware.Execute(ResolveRequestContext context, Action`1 next)\n
at Autofac.Core.Resolving.Middleware.CircularDependencyDetectorMiddleware.Execute(ResolveRequestContext context, Action`1 next)\n
at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, ResolveRequest request)\n
at Autofac.Core.Resolving.ResolveOperation.ExecuteOperation(ResolveRequest request)\n
at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable`1 parameters, Object& instance)\n
at Autofac.ResolutionExtensions.ResolveOptionalService(IComponentContext context, Service service, IEnumerable`1 parameters)\n
at lambda_method1546(Closure, IServiceProvider, Object[])\n
at Orleans.Runtime.ActivationDataActivatorProvider.ActivationDataActivator.CreateContext(GrainAddress activationAddress) in /_/src/Orleans.Runtime/Activation/ActivationDataActivatorProvider.cs:line 125\n
at Orleans.Runtime.GrainContextActivator.CreateInstance(GrainAddress address) in /_/src/Orleans.Runtime/Activation/IGrainContextActivator.cs:line 61\n
at Orleans.Runtime.Catalog.GetOrCreateActivation(GrainId& grainId, Dictionary`2 requestContextData, MigrationContext rehydrationContext) in /_/src/Orleans.Runtime/Catalog/Catalog.cs:line 265\n
at Orleans.Runtime.Messaging.MessageCenter.ReceiveMessage(Message msg) in /_/src/Orleans.Runtime/Messaging/MessageCenter.cs:line 518

0 comments on commit 4fccb00

Please sign in to comment.