Skip to content

ORLEANS0228: Detach durable grain calls

PropertyValue
SeverityError
CategoryUsage
Code fixNone

Durable task code calls Detached() or Detached(rootId) on a definition which runs as part of the execution which starts it: a DurableTask.Run step, an async DurableTask method, or a combinator such as DurableTask.WhenAll:

public async DurableTask CompleteAsync(string customer)
{
await Pack().WithId("pack");
// A local method runs as part of this execution, so starting it detached throws InvalidOperationException.
_ = SurveyAsync(customer).WithId("survey").Detached().Post();
}

A detached task is an independent root task. Its host stores the task and runs it on its own, after the starting execution completes and after the starting execution’s tree is deleted, so its definition is one which a host starts as a root task, such as a durable grain call, which the grain’s host stores as a request.

A step, an async DurableTask method, and a combinator are code of the starting execution: a replay of that execution re-creates them, and nothing else can. Starting one detached throws InvalidOperationException, before the start takes an identifier of the execution.

For attached and detached starts, see Starting and observing tasks.

Detach a durable grain call. Move the work into a durable method of a grain, and detach the call. The grain runs it as a root task:

public async DurableTask CompleteAndSurveyAsync(string customer)
{
await Pack().WithId("pack");
// The surveys grain stores and runs the call as a root task, which continues after this execution completes.
_ = GrainFactory.GetGrain<ICustomerSurveys>(customer).SendSurveyAsync(customer).WithId("survey").Detached().Post();
}

Start the work attached. When the execution can wait for the work, await it, or schedule it and observe its handle:

public async DurableTask CompleteThenSurveyAsync(string customer)
{
await Pack().WithId("pack");
// The step runs as a child of this execution, which waits for it.
await SurveyAsync(customer).WithId("survey");
}

Keep the diagnostic enabled: the start throws at run time.