Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Durable Entity creates NullReferenceException with Microsoft.Azure.Functions.Worker.Extensions.DurableTask.SqlServer #205

Open
Enlatic opened this issue Jan 18, 2024 · 5 comments
Labels
external Not strictly related to this project P1 Priority 1

Comments

@Enlatic
Copy link

Enlatic commented Jan 18, 2024

Hi.

I have slight problem. Dont know if it a configuration issue on my side or something else.

Currently migrating our software from ..NET6 -> .NET8 and from InProc to Isolated. All good works as intended. The Null Reference Exception shows its self when I switch from AzureStorage to SQL Server.

A bit of code to exemplify the issue.

[Function(nameof(ProcessData))]
 public async Task RunOrchestrator(
     [OrchestrationTrigger] TaskOrchestrationContext context)
 {
     ILogger logger = context.CreateReplaySafeLogger(nameof(ProcessData));
     var input = context.GetInput<string>();


     var result = await context.CallActivityAsync<RegionMix>("ActProcessData", input);

     var countryKey = string.IsNullOrEmpty(result.CountryCode) ? result.Country : result.CountryCode;
     await context.Entities.SignalEntityAsync(new EntityInstanceId(nameof(Entities.EnergyMix), countryKey), "Add", result);


 }

var result is a POCO.
Running this code, I get the NullReferenceException on SignalEntify.

My config is:
Microsoft.Azure.Functions.Worker - 1.20.1
Microsoft.Azure.Functions.Worker.Extensions.DurableTask - 1.1.0
Microsoft.Azure.Functions.Worker.Extensions.DurableTask.SqlServer - 1.2.2
Microsoft.Azure.Functions.Worker.Sdk - 1.16.4

host.json :)

{
  "version": "2.0",
  "extensions": {
    "http": {
      "routePrefix": ""
    },
    "durableTask": {
      "hubName": "%TaskHubConfig%",
      "storageProvider": {
        "type": "mssql",
        "connectionStringName": "Durable_SQLDB_Connection",
        "createDatabaseIfNotExists": true
      }
    }
  },
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      },
      "enableLiveMetricsFilters": true
    },
    "logLevel": {
      "default": "Information",
      "DurableTask.SqlServer": "Debug",
      "DurableTask.Core": "Debug"
    }
  }
}

After a bit of debugging.
The exception originates OrchestrationEntityContext class on DurableTask.Core

 internal void AdjustOutgoingMessage(string instanceId, RequestMessage requestMessage, DateTime? cappedTime, out string eventName)
 {
     if (cappedTime.HasValue)
     {
         eventName = EntityMessageEventNames.ScheduledRequestMessageEventName(cappedTime.Value);
     }
     else
     {
         this.messageSorter.LabelOutgoingMessage(
             requestMessage,
             instanceId,
             this.innerContext.CurrentUtcDateTime,
             this.innerContext.EntityParameters.EntityMessageReorderWindow);

         eventName = EntityMessageEventNames.RequestMessageEventName;
     }
 }

The this.innerContext.EntityParameters is not populated and is NULL.

Is this intentionally? If yes, how do I fix it...

//Daniel

@bachuv bachuv added bug Something isn't working P1 Priority 1 and removed Needs: Triage 🔍 labels Jan 30, 2024
@oleks9o6
Copy link

oleks9o6 commented Feb 7, 2024

It looks like it is rather due to changing the storage to MSSQL than .NET migration. I faced the same issue microsoft/durabletask-dotnet#246, and it seems that MSSQL storage might not support durable entities yet.

@cgillum
Copy link
Member

cgillum commented Feb 7, 2024

Durable Entities should be supported on the MSSQL backend. There are tests for the feature here.

However, our tests only target the in-proc implementation of entities. It's possible that there's a problem when using Durable Entities on MSSQL with the .NET Isolated worker, which has a different internal implementation. Will need to try and set up a local repro to see what's going on.

@oleks9o6
Copy link

oleks9o6 commented Feb 7, 2024

Durable Entities should be supported on the MSSQL backend. There are tests for the feature here.

However, our tests only target the in-proc implementation of entities. It's possible that there's a problem when using Durable Entities on MSSQL with the .NET Isolated worker, which has a different internal implementation. Will need to try and set up a local repro to see what's going on.

Thanks for confirming it should work. I provided a minimal repro example in the linked issue here microsoft/durabletask-dotnet#246. Let me know if you need any additional details.

@cgillum
Copy link
Member

cgillum commented Feb 8, 2024

Thanks, so based on the issue you linked to, it looks like new feature work is required to support entities in the .NET Isolated worker. I was able to reproduce the issue using the minimal repro you provided (thanks!) so I can use that as a starting point for ensuring that .NET Isolated entities work correctly.

@cgillum
Copy link
Member

cgillum commented Feb 28, 2024

The following PR in DTFx core should replace the null-ref exception with a friendlier exception: Azure/durabletask#1047.

@cgillum cgillum added external Not strictly related to this project and removed bug Something isn't working labels Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external Not strictly related to this project P1 Priority 1
Projects
None yet
Development

No branches or pull requests

4 participants