1
1
using System ;
2
2
using System . Collections . Generic ;
3
+ using System . Diagnostics ;
4
+ using System . Linq ;
3
5
using System . Threading . Tasks ;
4
6
using Cleipnir . ResilientFunctions . CoreRuntime . Invocation ;
5
7
using Cleipnir . ResilientFunctions . Domain ;
@@ -61,7 +63,11 @@ public async Task Start(string watchdogName)
61
63
{
62
64
var now = DateTime . UtcNow ;
63
65
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
+
65
71
foreach ( var sef in eligibleFunctions . WithRandomOffset ( ) )
66
72
{
67
73
if ( ! _asyncSemaphore . TryTake ( out var takenLock ) )
@@ -114,4 +120,19 @@ await _scheduleReInvoke(
114
120
goto Start ;
115
121
}
116
122
}
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
+ }
117
138
}
0 commit comments