ORLEANS0210: Run concurrent durable work through durable combinators
| Property | Value |
|---|---|
| Severity | Warning |
| Category | Usage |
| Code fix | None |
A durable task body passes durable work, such as lambdas which await durable tasks, to Task.WhenAll, Task.WhenAny, Task.WaitAll, or Task.WaitAny:
public async DurableTask<bool> ReserveAllAsync(int[] productIds){ // Each lambda schedules its child in input order, with a separate journal write for each invocation. var reserved = await Task.WhenAll(productIds.Select(async id => await Reserve(id).WithId($"reserve-{id}"))); return reserved.All(r => r);}Rule description
Section titled “Rule description”Enumerating the Select in this example invokes each lambda in input order, and its awaits capture the activation’s scheduler. Each child commits its invocation in a separate journal write. A durable fan-out combinator gives the inputs a shared durable identity and commits their invocations as a batch.
Task combinators also leave losing inputs running: Task.WhenAny returns while the other inputs continue, and nothing cancels or awaits them. Task.WaitAll and Task.WaitAny block the activation’s scheduler.
Durable combinators identify each input by its index beneath the combinator’s name, such as reserve/0 and reserve/1, schedule the inputs in one batch which one journal write commits, and record which input completed first, so every replay observes the same outcome.
For combinators, see Combinators and handles.
How to fix violations
Section titled “How to fix violations”Use DurableTask.WhenAll for results in input order:
public async DurableTask<bool> ReserveEveryLineAsync(int[] productIds){ // The inputs are reserve/0, reserve/1, and so on, in input order, and their invocations commit in one write. var reserved = await DurableTask.WhenAll(productIds.Select(Reserve)).WithId("reserve"); return reserved.All(r => r);}Use DurableTask.Race for the first result. Race requests cancellation of the other inputs and waits until each is terminal, so no input outlives it. DurableTask.WhenAny returns the first result and leaves the others running:
public async DurableTask<int> ReserveFromFirstWarehouseAsync(int[] warehouses){ // Instead of Task.WhenAny: the first warehouse to answer wins, and the others are canceled and awaited. var (index, _) = await DurableTask.Race(warehouses.Select(Reserve)).WithId("first-warehouse"); return warehouses[index];}Use DurableTask.ScheduleAll to start every input and continue with their handles, and DurableTask.WhenAllCompleted to wait for every outcome without throwing. To bound durable work with a timeout instead of racing it with Task.Delay, use the task’s WaitAsync or WaitUntilAsync.
When to suppress
Section titled “When to suppress”Suppress the diagnostic when the combined tasks perform no durable operations, which the analyzer can’t determine, for example when they call helpers in another assembly.
