ORLEANS0214: Derive a signal name for each repeated wait
| Property | Value |
|---|---|
| Severity | Info |
| Category | Usage |
| Code fix | None |
A durable task body calls WaitAsync or TryWaitAsync on a DurableSignal<T> inside a loop, and the signal isn’t derived with For:
public async DurableTask<bool> NegotiateAsync(int rounds){ for (var round = 1; round <= rounds; round++) { // Every iteration returns the first review, so one rejection rejects every round at once. var review = await Reviewed.WaitAsync(); if (review.Approved) { return true; } }
return false;}Rule description
Section titled “Rule description”A task records the first value which a sender delivers for each signal name, and returns that value to every wait for the name, including waits during replay. A later value for the same name is rejected as a conflict when it differs, and reported as a duplicate when it’s equal.
In the example, the first review rejects the contract. Every later round’s wait returns that rejection at once, so the negotiation ends after one review, and the reviewers’ later decisions are rejected.
For signals, see Signals.
How to fix violations
Section titled “How to fix violations”Derive a name for each occurrence with DurableSignal<T>.For, from a value which identifies it, such as the round number. Senders deliver each decision to the same derived signal, such as ContractGrain.Reviewed.For("round-2"):
public async DurableTask<bool> NegotiateEachRoundAsync(int rounds){ for (var round = 1; round <= rounds; round++) { // Each round waits for its own signal name: "reviewed/round-1", "reviewed/round-2", and so on. var review = await Reviewed.For($"round-{round}").WaitAsync(); if (review.Approved) { return true; } }
return false;}When to suppress
Section titled “When to suppress”Suppress the diagnostic for a loop which waits for the same one-time event in each iteration on purpose, for example one which rechecks a condition after the event arrived.
