Skip to content

Commit

Permalink
''
Browse files Browse the repository at this point in the history
  • Loading branch information
Release-Agent committed Apr 25, 2024
1 parent 3af97c1 commit 0a036ed
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2380,7 +2380,7 @@ internal async Task<HttpResponseMessage> Command_WebExecuteAsync(string queryStr
retry = ShouldRetryWebAPI(ex, retryCount, maxRetryCount, retryPauseTime, out isThrottled);
if (retry)
{
Utilities.RetryRequest(null, requestTrackingId, TimeSpan.Zero, logDt, logEntry, SessionTrackingId, disableConnectionLocking, _retryPauseTimeRunning, ex, errorStringCheck, ref retryCount, isThrottled, webUriReq: $"{method} {queryString}");
retryCount = await Utilities.RetryRequest(null, requestTrackingId, TimeSpan.Zero, logDt, logEntry, SessionTrackingId, disableConnectionLocking, _retryPauseTimeRunning, ex, errorStringCheck, retryCount, isThrottled, webUriReq: $"{method} {queryString}").ConfigureAwait(false);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,52 +1,55 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<RootNamespace>Microsoft.PowerPlatform.Dataverse.Client</RootNamespace>
<ComponentAreaName>DataverseClient</ComponentAreaName>
<SignAssembly>true</SignAssembly>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
<Import Project="..\..\..\Build.Common.core.props" />
<PropertyGroup>
<RootNamespace>Microsoft.PowerPlatform.Dataverse.Client</RootNamespace>
<ComponentAreaName>DataverseClient</ComponentAreaName>
<SignAssembly>true</SignAssembly>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
<Import Project="..\..\..\Build.Common.core.props" />

<PropertyGroup>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<DocumentationFile>$(OutDir)\Microsoft.PowerPlatform.Dataverse.Client.xml</DocumentationFile>
<AnalysisLevel>6.0</AnalysisLevel>
</PropertyGroup>
<PropertyGroup>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<DocumentationFile>$(OutDir)\Microsoft.PowerPlatform.Dataverse.Client.xml</DocumentationFile>
<AnalysisLevel>6.0</AnalysisLevel>
</PropertyGroup>


<ItemGroup>
<Compile Remove="UnitTestBehaviors\**" />
<Compile Remove="UnitTests\**" />
<EmbeddedResource Remove="UnitTestBehaviors\**" />
<EmbeddedResource Remove="UnitTests\**" />
<None Remove="UnitTestBehaviors\**" />
<None Remove="UnitTests\**" />
</ItemGroup>
<ItemGroup>
<Compile Remove="UnitTestBehaviors\**" />
<Compile Remove="UnitTests\**" />
<EmbeddedResource Remove="UnitTestBehaviors\**" />
<EmbeddedResource Remove="UnitTests\**" />
<None Remove="UnitTestBehaviors\**" />
<None Remove="UnitTests\**" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Xrm.Sdk" Version="$(PackageVersion_CdsSdk)" />
<PackageReference Include="Microsoft.Crm.Sdk.Proxy" Version="$(PackageVersion_CrmProxy)" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="$(PackageVersion_Microsoft_Extensions)" />
<PackageReference Include="Microsoft.Extensions.Http" Version="$(PackageVersion_Microsoft_Extensions)" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="$(PackageVersion_Microsoft_Extensions)" />
<PackageReference Include="Microsoft.Identity.Client" version="$(PackageVersion_MSAL)" />
<PackageReference Include="Microsoft.Rest.ClientRuntime" Version="$(PackageVersion_RestClientRuntime)" />
<PackageReference Include="Microsoft.VisualBasic" Version="10.3.0" />
<PackageReference Include="Newtonsoft.Json" Version="$(PackageVersion_Newtonsoft)" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="$(PackageVersion_SystemConfigurationConfigurationManager)" />
<!--<PackageReference Include="System.Security.Cryptography.Algorithms" Version="4.3.1" />
<ItemGroup>
<PackageReference Include="Microsoft.Xrm.Sdk" Version="$(PackageVersion_CdsSdk)" />
<PackageReference Include="Microsoft.Crm.Sdk.Proxy" Version="$(PackageVersion_CrmProxy)" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="$(PackageVersion_Microsoft_Extensions)" />
<PackageReference Include="Microsoft.Extensions.Http" Version="$(PackageVersion_Microsoft_Extensions)" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="$(PackageVersion_Microsoft_Extensions)" />
<PackageReference Include="Microsoft.Identity.Client" version="$(PackageVersion_MSAL)" />
<PackageReference Include="Microsoft.Rest.ClientRuntime" Version="$(PackageVersion_RestClientRuntime)" />
<PackageReference Include="Microsoft.VisualBasic" Version="10.3.0" />
<PackageReference Include="System.ServiceModel.Http" version="4.10.3" />
<PackageReference Include="System.ServiceModel.Primitives" version="4.10.3" />
<PackageReference Include="Newtonsoft.Json" Version="$(PackageVersion_Newtonsoft)" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="$(PackageVersion_SystemConfigurationConfigurationManager)" />
<!--<PackageReference Include="System.Security.Cryptography.Algorithms" Version="4.3.1" />
<PackageReference Include="System.Security.Cryptography.ProtectedData" Version="4.7.0" />
<PackageReference Include="System.Security.Permissions" Version="$(PackageVersion_SystemSecurityPermissions)" /> -->
<PackageReference Include="System.Text.Json" Version="$(PackageVersion_SystemTextJson)" />
<PackageReference Include="Microsoft.Identity.Client.Extensions.Msal" Version="$(PackageVersion_MSAL)" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="$(PackageVersion_Microsoft_Extensions)" />
<!--<PackageReference Include="System.Drawing.Common" Version="5.0.3" />--> <!-- explict add to deal with CVE-2021-24112 -->
</ItemGroup>
<PackageReference Include="System.Text.Json" Version="$(PackageVersion_SystemTextJson)" />
<PackageReference Include="Microsoft.Identity.Client.Extensions.Msal" Version="$(PackageVersion_MSAL)" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="$(PackageVersion_Microsoft_Extensions)" />
<!--<PackageReference Include="System.Drawing.Common" Version="5.0.3" />-->
<!-- explict add to deal with CVE-2021-24112 -->
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net462' or '$(TargetFramework)' == 'net472' or '$(TargetFramework)' == 'net48'">
<Reference Include="System.Web" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net462' or '$(TargetFramework)' == 'net472' or '$(TargetFramework)' == 'net48'">
<Reference Include="System.Web" />
</ItemGroup>

</Project>
7 changes: 5 additions & 2 deletions src/GeneralTools/DataverseClient/Client/ServiceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1871,7 +1871,7 @@ internal async Task<OrganizationResponse> Command_ExecuteAsyncImpl(OrganizationR
retry = ShouldRetry(req, ex, retryCount, out isThrottled);
if (retry)
{
Utilities.RetryRequest(req, requestTrackingId, LockWait, logDt, _logEntry, SessionTrackingId, _disableConnectionLocking, _retryPauseTimeRunning, ex, errorStringCheck, ref retryCount, isThrottled);
retryCount = await Utilities.RetryRequest(req, requestTrackingId, LockWait, logDt, _logEntry, SessionTrackingId, _disableConnectionLocking, _retryPauseTimeRunning, ex, errorStringCheck, retryCount, isThrottled).ConfigureAwait(false);
}
else
{
Expand Down Expand Up @@ -1978,7 +1978,10 @@ internal OrganizationResponse Command_Execute(OrganizationRequest req, string er
retry = ShouldRetry(req, ex, retryCount, out isThrottled);
if (retry)
{
Utilities.RetryRequest(req, requestTrackingId, LockWait, logDt, _logEntry, SessionTrackingId, _disableConnectionLocking, _retryPauseTimeRunning, ex, errorStringCheck, ref retryCount, isThrottled);
Task.Run(async () =>
{
retryCount = await Utilities.RetryRequest(req, requestTrackingId, LockWait, logDt, _logEntry, SessionTrackingId, _disableConnectionLocking, _retryPauseTimeRunning, ex, errorStringCheck, retryCount, isThrottled).ConfigureAwait(false);
}).ConfigureAwait(false).GetAwaiter().GetResult();
}
else
{
Expand Down
7 changes: 4 additions & 3 deletions src/GeneralTools/DataverseClient/Client/Utils/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -446,14 +446,15 @@ internal static string ConstructWebApiRequestUrl(OrganizationRequest request, Ht
/// <param name="retryCount">retryCount</param>
/// <param name="isThrottled">when set indicated this was caused by a Throttle</param>
/// <param name="webUriReq"></param>
internal static void RetryRequest(OrganizationRequest req, Guid requestTrackingId, TimeSpan LockWait, Stopwatch logDt,
internal static async Task<int> RetryRequest(OrganizationRequest req, Guid requestTrackingId, TimeSpan LockWait, Stopwatch logDt,
DataverseTraceLogger logEntry, Guid? sessionTrackingId, bool disableConnectionLocking, TimeSpan retryPauseTimeRunning,
Exception ex, string errorStringCheck, ref int retryCount, bool isThrottled, string webUriReq = "")
Exception ex, string errorStringCheck, int retryCount, bool isThrottled, string webUriReq = "")
{
retryCount++;
logEntry.LogFailure(req, requestTrackingId, sessionTrackingId, disableConnectionLocking, LockWait, logDt, ex, errorStringCheck, webUriMessageReq: webUriReq);
logEntry.LogRetry(retryCount, req, retryPauseTimeRunning, isThrottled: isThrottled);
Task.Delay(retryPauseTimeRunning);
await Task.Delay(retryPauseTimeRunning).ConfigureAwait(false);
return retryCount;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Microsoft.Xrm.Sdk.Metadata;
using Microsoft.Xrm.Sdk.Query;
using Moq;
using Newtonsoft.Json.Bson;
using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand Down Expand Up @@ -752,6 +753,57 @@ public void TestResponseHeaderBehavior()
Assert.Equal(defaultDOP, cli.RecommendedDegreesOfParallelism);
}

[Fact]
public void RetryOperationTest()
{
Mock<IOrganizationService> orgSvc = null;
Mock<MoqHttpMessagehander> fakHttpMethodHander = null;
ServiceClient cli = null;
testSupport.SetupMockAndSupport(out orgSvc, out fakHttpMethodHander, out cli);

Guid testGuid = Guid.NewGuid();

CreateRequest exampleRequest = new CreateRequest();
exampleRequest.Target = new Entity("account");
exampleRequest.Target.Attributes.Add("id", testGuid);

Stopwatch testwatch = Stopwatch.StartNew();
int retrycount = 0;

Task.Run(async () =>
{
retrycount = await Utilities.RetryRequest(exampleRequest, testGuid, new TimeSpan(0), testwatch, cli._logEntry, null, false, new TimeSpan(0, 0, 1), new Exception("Fake_TEST_MSG"), "test retry logic", retrycount, false, null).ConfigureAwait(false);
}).ConfigureAwait(false).GetAwaiter().GetResult();
Assert.True(retrycount == 1);
Task.Run(async () =>
{
retrycount = await Utilities.RetryRequest(exampleRequest, testGuid, new TimeSpan(0), testwatch, cli._logEntry, null, false, new TimeSpan(0, 0, 1), new Exception("Fake_TEST_MSG"), "test retry logic", retrycount, false, null).ConfigureAwait(false);
}).ConfigureAwait(false).GetAwaiter().GetResult();
Assert.True(retrycount == 2);
}

[Fact]
public async void RetryOperationAyncTest()
{
Mock<IOrganizationService> orgSvc = null;
Mock<MoqHttpMessagehander> fakHttpMethodHander = null;
ServiceClient cli = null;
testSupport.SetupMockAndSupport(out orgSvc, out fakHttpMethodHander, out cli);

Guid testGuid = Guid.NewGuid();

CreateRequest exampleRequest = new CreateRequest();
exampleRequest.Target = new Entity("account");
exampleRequest.Target.Attributes.Add("id", testGuid);

Stopwatch testwatch = Stopwatch.StartNew();
int retrycount = 0;

retrycount = await Utilities.RetryRequest(exampleRequest, testGuid, new TimeSpan(0), testwatch, cli._logEntry, null, false, new TimeSpan(0, 0, 1), new Exception("Fake_TEST_MSG"), "test retry logic", retrycount, false, null).ConfigureAwait(false);
Assert.True(retrycount == 1);
retrycount = await Utilities.RetryRequest(exampleRequest, testGuid, new TimeSpan(0), testwatch, cli._logEntry, null, false, new TimeSpan(0, 0, 1), new Exception("Fake_TEST_MSG"), "test retry logic", retrycount, false, null).ConfigureAwait(false);
Assert.True(retrycount == 2);
}

#region LiveConnectedTests

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ Notice:
Note: Only AD on FullFramework, OAuth, Certificate, ClientSecret Authentication types are supported at this time.

++CURRENTRELEASEID++
Fix for Retry hang introduced in 1.1.21:
Dependency Changes:
Added:
System.ServiceModel.Http 4.10.3
System.ServiceModel.Primitives 4.10.3

1.1.21:
Updated Core SDK to 9.2.24044.9795
Added new ServiceClient method for creating requests called "RequestBuilder" - will allow you to create a request and customized header, user, and other properties as part of there request generation.
Dependency Changes:
Expand Down
3 changes: 2 additions & 1 deletion src/nuspecs/Microsoft.PowerPlatform.Dataverse.Client.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
<dependency id="System.Runtime.Serialization.Primitives" version="4.3.0" exclude="Build,Analyzers" />
<dependency id="System.Runtime.Serialization.Xml" version="4.3.0" exclude="Build,Analyzers" />
<dependency id="System.Security.Permissions" version="[$PackageVersion_SystemSecurityPermissions$,)" exclude="Build,Analyzers" />
<dependency id="System.ServiceModel.Http" version="4.10.2" exclude="Build,Analyzers" />
<dependency id="System.ServiceModel.Http" version="4.10.3" exclude="Build,Analyzers" />
<dependency id="System.ServiceModel.Primitives" version="4.10.3" exclude="Build,Analyzers" />
<dependency id="System.Text.Json" version="[$PackageVersion_SystemTextJson$,)" exclude="Build,Analyzers" />
<dependency id="Microsoft.Extensions.DependencyInjection" version="[$PackageVersion_Microsoft_Extensions$,)" exclude="Build,Analyzers" />
<dependency id="Microsoft.Extensions.Http" version="[$PackageVersion_Microsoft_Extensions$,)" exclude="Build,Analyzers" />
Expand Down

0 comments on commit 0a036ed

Please sign in to comment.