ORLEANS0208: Give each durable operation call site its own name
| Property | Value |
|---|---|
| Severity | Warning |
| Category | Usage |
| Code fix | None |
Two call sites of WithId, or two call sites of DurableTask.RunInline, in one durable task body pass the same constant name, and one run can reach both. Call sites in mutually exclusive branches, such as the two arms of an if statement, and one call site which a loop repeats aren’t reported. Outside durable task bodies, such as in clients and ordinary grain methods, WithId names root tasks, which the rule doesn’t check:
public async DurableTask OnboardAsync(string customer){ await Send(customer, "Welcome").WithId("email"); await DurableTask.Delay(TimeSpan.FromDays(7)).WithId("first-week");
// Recorded as "email$2". After a deployment removes the welcome email, a replay identifies this call as "email", // which holds the welcome email's record. await Send(customer, "Tips for your first week").WithId("email");}Rule description
Section titled “Rule description”A name which one run repeats identifies its later occurrences by their order: the first occurrence is email, and the second is email$2. Each identifier then depends on how many earlier call sites used the name.
When a deployment removes the welcome email while executions are pending, the replay of an execution which already sent both emails names the tips email email. That identifier holds the welcome email’s record:
- For a local step, the replay returns the welcome email’s recorded completion, and the tips email’s own record,
email$2, is never reached. - For a call to another grain, the replay finds another request under the identifier, diverges, and stalls the execution.
Distinct names keep each call site’s identifier when other call sites are added, removed, or reordered. For how identifiers are constructed, see Task identity and references.
For identifiers and versioning, see Replay-safety rules.
How to fix violations
Section titled “How to fix violations”Give each call site its own name:
public async DurableTask OnboardWithNamesAsync(string customer){ await Send(customer, "Welcome").WithId("welcome-email"); await DurableTask.Delay(TimeSpan.FromDays(7)).WithId("first-week"); await Send(customer, "Tips for your first week").WithId("tips-email");}Name a repeated call site once. A call site in a loop keeps one name, and the runtime numbers its occurrences in order. To identify each occurrence by its input instead, derive the name from a stable value, such as $"lesson-{index}":
public async DurableTask SendSeriesAsync(string customer, string[] subjects){ // One call site which a loop repeats is named once: its occurrences are "lesson", "lesson$2", and so on. A name // derived from each input also identifies it. foreach (var subject in subjects) { await Send(customer, subject).WithId("lesson"); }}When to suppress
Section titled “When to suppress”Suppress the diagnostic when the call sites can’t both run in one execution, through a condition which the analyzer doesn’t follow.
