Skip to content

Commit 32ca2b7

Browse files
committed
Fixed debugging race-condition in ReInvoker
1 parent 94e93dc commit 32ca2b7

File tree

1 file changed

+22
-1
lines changed
  • Core/Cleipnir.ResilientFunctions/CoreRuntime/Watchdogs

1 file changed

+22
-1
lines changed

Core/Cleipnir.ResilientFunctions/CoreRuntime/Watchdogs/ReInvoker.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Linq;
35
using System.Threading.Tasks;
46
using Cleipnir.ResilientFunctions.CoreRuntime.Invocation;
57
using Cleipnir.ResilientFunctions.Domain;
@@ -61,7 +63,11 @@ public async Task Start(string watchdogName)
6163
{
6264
var now = DateTime.UtcNow;
6365

64-
var eligibleFunctions = await _getEligibleFunctions(_functionTypeId, _functionStore, DateTime.UtcNow.Ticks);
66+
var eligibleFunctions = await _getEligibleFunctions(_functionTypeId, _functionStore, now.Ticks);
67+
#if DEBUG
68+
eligibleFunctions = await ReAssertCrashedFunctions(eligibleFunctions, now);
69+
#endif
70+
6571
foreach (var sef in eligibleFunctions.WithRandomOffset())
6672
{
6773
if (!_asyncSemaphore.TryTake(out var takenLock))
@@ -114,4 +120,19 @@ await _scheduleReInvoke(
114120
goto Start;
115121
}
116122
}
123+
124+
private async Task<IReadOnlyList<InstanceIdAndEpoch>> ReAssertCrashedFunctions(IReadOnlyList<InstanceIdAndEpoch> eligibleFunctions, DateTime now)
125+
{
126+
//race-condition fix between re-invoker and lease-updater. Task.Delays are not respected when debugging.
127+
//fix is to allow lease updater to update lease before crashed watchdog asserts that the functions in question has crashed
128+
129+
if (eligibleFunctions.Count == 0 || !Debugger.IsAttached)
130+
return eligibleFunctions;
131+
132+
await Task.Delay(500);
133+
var eligibleFunctionsRepeated =
134+
(await _getEligibleFunctions(_functionTypeId, _functionStore, now.Ticks)).ToHashSet();
135+
136+
return eligibleFunctions.Where(ie => eligibleFunctionsRepeated.Contains(ie)).ToList();
137+
}
117138
}

0 commit comments

Comments
 (0)