PowerPlatform-DataverseServiceClient: Memory leak on RetrieveMultipleAsync
In the last 3 releases:
- 1.1.22
- 1.1.27
- 1.1.32
The memory leak as described in Issue #207 has returned.
Version 1.1.17 however does not have this issue.
As per #207 this new leak is also only an issue when using RetrieveMultipleAsync, using RetrieveMultiple works as expected
As per [https://github.com/microsoft/PowerPlatform-DataverseServiceClient/issues/207#issuecomment-983838048](This reply on 207 ) I tested the following and still saw memory consumption continue to rise and never be released:
- Smaller Batch sizes
- Pulling from narrow tables, (The example below is using ActivityParty which is only 33 columns wide)
Here is some sample code from a .NET 8.0 Console App which reproduces the issue:
using Microsoft.PowerPlatform.Dataverse.Client;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
internal class Program
{
private static async Task Main(string[] args)
{
string InstanceURL = "<Dynamics URL Here>";
string ClientId = "<ClientId Here>";
string ClientSecret = "<ClientSecret Here>";
ServiceClient.MaxConnectionTimeout = TimeSpan.FromMinutes(60);
ServiceClient client = new ServiceClient($"AuthType=ClientSecret; Url={InstanceURL}; ClientId={ClientId}; ClientSecret={ClientSecret}")
{
EnableAffinityCookie = false,
};
QueryExpression query = new()
{
PageInfo = new PagingInfo
{
PagingCookie = "",
PageNumber = 1,
Count = 5000,
},
EntityName = "activityparty",
Distinct = false,
NoLock = true,
ColumnSet = new ColumnSet(true),
};
bool MoreRecords = false;
long TotalCount = 0;
do
{
EntityCollection QueryResult = await client.RetrieveMultipleAsync(query);
TotalCount += QueryResult?.Entities?.Count ?? 0;
MoreRecords = QueryResult?.MoreRecords ?? false;
if (MoreRecords)
{
query.PageInfo.PagingCookie = QueryResult?.PagingCookie ?? string.Empty;
query.PageInfo.PageNumber++;
}
}
while (MoreRecords);
Console.WriteLine($"Downloaded {TotalCount:N0} Records");
}
}
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 17 (7 by maintainers)
Folks… Good news here. in cooperation with the .net team we found the root cause of the issue, its a fix inside .net itself so it’s going into the fix train for .net now.
We are being told the fix will get into the 8.1.2 Nuget packages for https://www.nuget.org/packages/System.ServiceModel.Http We will pick that up as a dependency shortly after it drops.
Ok, that help clarify what you’re seeing @lukeswanton, We will have a look now that we understand your seeing it as a general regression and not use case specific.
as for what changed: in .22, the underlying ServiceModule libs were bumped due to security issues in lower-level transient dependencies. in .32, the underlying ServiceModule subsystem was forked for .net core and .net framework due to .net core choices that broke backward compatibility.