Skip to content

Commit 06484b4

Browse files
committed
Prevent two process loops if heartbeat error
1 parent c24a99c commit 06484b4

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/IntelOrca.Biohazard.BioRand.Common/RandomizerAgent.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,22 @@ private async Task RunInternalAsync(CancellationToken ct = default)
8787
{
8888
try
8989
{
90-
await Task.WhenAny(
91-
RunStatusLoopAsync(ct),
92-
RunProcessLoopAsync(ct));
90+
var localCts = new CancellationTokenSource();
91+
var linked = CancellationTokenSource.CreateLinkedTokenSource(localCts.Token, ct);
92+
var a = RunStatusLoopAsync(linked.Token);
93+
var b = RunProcessLoopAsync(linked.Token);
94+
try
95+
{
96+
await Task.WhenAny(a, b);
97+
}
98+
finally
99+
{
100+
localCts.Cancel();
101+
await Task.WhenAll(a, b);
102+
}
103+
}
104+
catch
105+
{
93106
}
94107
finally
95108
{

0 commit comments

Comments
 (0)