From f8577afcffe8099a33e4de6277c8beb60409d49f Mon Sep 17 00:00:00 2001 From: Norm Johanson Date: Tue, 7 Jan 2025 16:45:16 -0800 Subject: [PATCH] Fix test tool hanging when restarting debugging session. --- .../Services/LambdaRuntimeAPI.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Services/LambdaRuntimeAPI.cs b/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Services/LambdaRuntimeAPI.cs index fc088d186..bbf02f0c2 100644 --- a/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Services/LambdaRuntimeAPI.cs +++ b/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Services/LambdaRuntimeAPI.cs @@ -92,10 +92,24 @@ public async Task GetNextInvocation(HttpContext ctx, string functionName) var runtimeDataStore = _runtimeApiDataStoreManager.GetLambdaRuntimeDataStore(functionName); EventContainer? activeEvent; - while (!runtimeDataStore.TryActivateEvent(out activeEvent)) + + // A Lambda function should never call to get the next event till it was done + // processing the active event and there is no more active event. If there + // is an active event still executing that most likely means the previous debug session was + // killed leaving the event active. In that case resend the active event + // to restart debugging the event. + if (runtimeDataStore.ActiveEvent != null && runtimeDataStore.ActiveEvent.EventStatus == EventContainer.Status.Executing) { - await Task.Delay(TimeSpan.FromMilliseconds(100)); + activeEvent = runtimeDataStore.ActiveEvent; } + else + { + while (!runtimeDataStore.TryActivateEvent(out activeEvent)) + { + await Task.Delay(TimeSpan.FromMilliseconds(100)); + } + } + if (activeEvent == null) return;