ORLEANS0219: Await, combine, or return the handles of scheduled children
| Property | Value |
|---|---|
| Severity | Info |
| Category | Usage |
| Code fix | None |
A durable task body schedules an attached child with ScheduleAsync and discards the returned handle, or holds it in a local whose only uses read its properties, such as Id:
public async DurableTask DispatchAsync(string customer){ // Starts the notice and discards its handle: the notice's failure reaches no code. await Notify(customer).WithId("notify").ScheduleAsync(); await Pack().WithId("pack");}Rule description
Section titled “Rule description”In a durable task body, ScheduleAsync starts an attached child and returns its handle once the child’s host has accepted and stored the child. The execution owns the child: the execution’s cancellation reaches it, and deleting the execution’s tree, once the execution is terminal, cancels a child which is still running. The child’s result and failure reach only code which observes the handle.
In the example, the body completes while the notice can still be running. A notice which fails leaves the order dispatched with no record of the failure in the workflow, and a notice which is still running when the execution’s tree is deleted is canceled.
For attached and detached starts, see Starting and observing tasks.
How to fix violations
Section titled “How to fix violations”Await the handle. The child runs while the body continues, and the body observes its outcome before it completes:
public async DurableTask DispatchAndNotifyAsync(string customer){ // The notice runs while the body packs, and the body observes its outcome before it completes. var notice = await Notify(customer).WithId("notify").ScheduleAsync(); await Pack().WithId("pack"); await notice;}Pass the handle to a combinator. ScheduledTask.WhenAll waits for every handle and throws the first failure in input order:
public async DurableTask DispatchAndInvoiceAsync(string customer){ var notice = await Notify(customer).WithId("notify").ScheduleAsync(); var invoice = await Invoice(customer).WithId("invoice").ScheduleAsync(); await Pack().WithId("pack"); await ScheduledTask.WhenAll([notice, invoice]);}Return the handle. A body which returns the handle passes the observation to its caller.
Detach work which outlives the execution. Detached() starts an independent root task, which continues after the execution completes and after its tree is deleted:
public async DurableTask DispatchAndSurveyAsync(string customer){ await Pack().WithId("pack");
// A durable grain call, started as an independent root task, which continues after this execution completes and // is deleted. await GrainFactory.GetGrain<ICustomerSurveys>(customer).SendSurveyAsync(customer).WithId("survey").Detached().ScheduleAsync();}When to suppress
Section titled “When to suppress”Suppress the diagnostic for a child whose outcome the workflow ignores, and which may stop when the execution’s tree is deleted, such as a best-effort cache warm-up.
