Skip to content

Commit f8577af

Browse files
committed
Fix test tool hanging when restarting debugging session.
1 parent ec8f736 commit f8577af

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Services/LambdaRuntimeAPI.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,24 @@ public async Task GetNextInvocation(HttpContext ctx, string functionName)
9292
var runtimeDataStore = _runtimeApiDataStoreManager.GetLambdaRuntimeDataStore(functionName);
9393

9494
EventContainer? activeEvent;
95-
while (!runtimeDataStore.TryActivateEvent(out activeEvent))
95+
96+
// A Lambda function should never call to get the next event till it was done
97+
// processing the active event and there is no more active event. If there
98+
// is an active event still executing that most likely means the previous debug session was
99+
// killed leaving the event active. In that case resend the active event
100+
// to restart debugging the event.
101+
if (runtimeDataStore.ActiveEvent != null && runtimeDataStore.ActiveEvent.EventStatus == EventContainer.Status.Executing)
96102
{
97-
await Task.Delay(TimeSpan.FromMilliseconds(100));
103+
activeEvent = runtimeDataStore.ActiveEvent;
98104
}
105+
else
106+
{
107+
while (!runtimeDataStore.TryActivateEvent(out activeEvent))
108+
{
109+
await Task.Delay(TimeSpan.FromMilliseconds(100));
110+
}
111+
}
112+
99113

100114
if (activeEvent == null)
101115
return;

0 commit comments

Comments
 (0)