From 400e7cba72891431cc719cf2b6eff47223d9b930 Mon Sep 17 00:00:00 2001 From: Aaron Stannard Date: Tue, 24 Dec 2024 09:42:10 -0600 Subject: [PATCH] close #7437 - fix KeyNotFoundException in DelegatingSupervisorStrategy (#7438) --- .../DelegatingSupervisorStrategy.cs | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/core/Akka.TestKit/DelegatingSupervisorStrategy.cs b/src/core/Akka.TestKit/DelegatingSupervisorStrategy.cs index e0649fb2667..46701517894 100644 --- a/src/core/Akka.TestKit/DelegatingSupervisorStrategy.cs +++ b/src/core/Akka.TestKit/DelegatingSupervisorStrategy.cs @@ -22,15 +22,19 @@ public class DelegatingSupervisorStrategy : SupervisorStrategy protected override Directive Handle(IActorRef child, Exception exception) { - var childDelegate = Delegates[child]; - var handleMethod = typeof(SupervisorStrategy).GetMethod( - name: "Handle", - bindingAttr: BindingFlags.Instance | BindingFlags.NonPublic, - binder: Type.DefaultBinder, - types: new[] {typeof(IActorRef), typeof(Exception)}, - modifiers: null); - var result = (Directive) handleMethod.Invoke(childDelegate, new object[]{ child, exception }); - return result; + if(Delegates.TryGetValue(child, out var childDelegate)) + { + var handleMethod = typeof(SupervisorStrategy).GetMethod( + name: "Handle", + bindingAttr: BindingFlags.Instance | BindingFlags.NonPublic, + binder: Type.DefaultBinder, + types: new[] {typeof(IActorRef), typeof(Exception)}, + modifiers: null); + var result = (Directive) handleMethod.Invoke(childDelegate, new object[]{ child, exception }); + return result; + } + + return DefaultDecider.Decide(exception); } public override void ProcessFailure(IActorContext context, bool restart, IActorRef child, Exception cause, ChildRestartStats stats,