durabletask-dotnet: Unexplainable "Non-Deterministic workflow detected" errors after migrating in-process functions to isolated-mode
Hello everyone,
We recently migrated an existing .NET 6 Durable Functions application from the in-process mode to the isolated-mode SDK. After deploying the application to Azure, we noticed a lot of “Non-deterministic workflow detected” errors suddenly appearing in our Orchestrations, that we cannot find the root cause for. The problematic errors always look like this:
Non-Deterministic workflow detected: A previous execution of this orchestration scheduled an activity task with sequence ID 0 and name ‘SomeActivity’ (version ‘’), but the current replay execution hasn’t (yet?) scheduled this task. Was a change made to the orchestrator code after this instance had already started running?
This error occurs even with completely new Orchestrations that were created after the Deployment, but also with terminated, purged and restarted Orchestrations. We have some Orchestrations that we had to purge and restart almost 10 times over the course of a few days now, because the error always re-appears randomly.
When this error occurs, the history always contains an entry like this, that gets the eventId 0 as the last written history event, which will of course clash with any regular entry that had the initial eventId 0:
The error also happens at completely different locations. Sometimes it happens even bevor the first acitivity of an orchestrator completes, sometimes it happens after the nth activity. And it also happens to multiple types of Orchestrators with very different code flows. We could not yet determine any commonality between the affected Orchestrators. The only thing that I can say for sure is that the more often an Orchestrator gets “woken up”, the higher the probability that the error occurs.
For example, we do have timer based code that looks like this:
private async Task<TrackingEvent> WaitForEvents(
TaskOrchestrationContext context,
EventsInput input,
ILogger replaySafeLogger,
CancellationToken cancellationToken = default)
{
ShipmentTrackingEvent? found = null;
while (found is null)
{
var nextCheck = context.CurrentUtcDateTime.Add(TimeSpan.FromMinutes(10));
replaySafeLogger.LogInformation("...");
await context.CreateTimer(nextCheck, cancellationToken);
var retryPolicy = new RetryPolicy(...);
found = await context.CallActivityAsync<TrackingEvent?>(
"PollServiceActivity",
input,
new TaskOptions(TaskRetryOptions.FromRetryPolicy(retryPolicy)));
}
return found;
}
The Orchestrator using the above code fails the most, because it is woken up every 10 Minutes. Sometimes it fails on the first iteration, sometimes it takes up to 10 loops with the timer to fail, but most of the time, we have to restart it at least once in its lifetime.
Because we have robust idempotency and a good termination/purge/restart logic, we can manage at the moment, but it does not inspire confidence in the isolated-mode Durable Task Framework at the moment.
Some more info:
- The App is .NET 6 based and runs on a DOTNET-ISOLATED|NET6.0 function app service.
- We use the default Azure Storage backend, no Netherite or other.
- The error also does not seem to appear when running locally with Azurite, otherwise our tests would have shown that earlier
- We chose to keep Newtonsoft.Json as Serialization library for the first deployment, to not break any existing serialized data. We use this in our
ConfigureFunctionsWorkerDefaults:
builder.Services.Configure<WorkerOptions>(
workerOptions =>
{
var settings = NewtonsoftJsonObjectSerializer.CreateJsonSerializerSettings();
settings.ContractResolver = new CamelCasePropertyNamesContractResolver();
settings.NullValueHandling = NullValueHandling.Ignore;
workerOptions.Serializer = new NewtonsoftJsonObjectSerializer(settings);
});
- Library versions that our App uses:
<PackageReference Include="Azure.Data.Tables" Version="12.8.0" />
<PackageReference Include="Microsoft.Azure.Core.NewtonsoftJson" Version="1.0.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.14.1" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.0.0-preview4" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.10.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.DurableTask" Version="1.0.2" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Timer" Version="4.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.AzureAppConfiguration" Version="5.0.0" />
Any help would be greatly appreciated.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 30 (17 by maintainers)
Update: It has been a few days without any incident. I can only conclude that the workaround in the middleware seems to help, the error is gone. I can work with that. Thanks for your support, and hopefully fixing this in the long run on your side won’t be too much of a hassle.
I will observe it a little more, but I think we had a breakthrough here! I deployed the workaround to our testing system, and after some promising initial tests, I felt brave and lucky and deployed that fix also to production, because it was low-risk. I can confirm, that since then there has not been a single more occurrence of the error. I guess that was it.
Here is the workaround code (taken and modified from your link, thanks for that):
I guess this workaround works fine for us, until you can find a way to build a proper fix. Out of curiosity, do you have tests that contain middleware as part of the pipeline? If yes, what makes our little middleware different than that?
I would also suggest that you update the docs with an info that the current DF version might break with custom middleware in the pipeline. Having a useable middleware pipeline was one of the major advantages of the isolated-mode functions imho, and this will probably break a lot of people’s integrations in the future, if they don’t know about it.
Again, thanks for being so responsive and supportive on this issue. This was a tough one.
Hi @Schmaga:
I’ve created a general tracking issue for this bug here: https://github.com/microsoft/durabletask-dotnet/issues/158 Since we investigated and found a workaround for your case, I’ll be closing this thread to centralize communications on that new tracking issue. Please subscribe to it for updates, and thanks for your help again 😃
@nilsmehlhorn, @Schmaga:
I’m pretty close to having a package to share. If all goes well, I might have something to share tomorrow (Friday) or Monday at the latest.
Yeah, nothing concerning with that versioning strategy.
Looking at the history and code, we are failing on the very first action taken. There is no parallelism, no branching, nothing tricky about that part of the code, it is a plain ol’ activity call. Why are we failing there though? To me, this sounds like history is becoming corrupted somehow. Where or how I do not know. Is it happening in the backend persistence layer? Is it happening in some layer in memory? How exactly is it becoming corrupted?
@davidmrdavid if your logging PR doesn’t already include it, it would be helpful to have a mode to essentially print out a history diff at time of failure. What history do we have loaded, and what action(s) has the orchestrator taken so far (including the one that caused the non-determinism failure)?
@davidmrdavid