Skip to content

Commit 0df698d

Browse files
author
Kamran Khan
committed
Add timeout of 10 minutes on ADE related HTTP calls
1 parent 5a9e883 commit 0df698d

File tree

4 files changed

+51
-8
lines changed

4 files changed

+51
-8
lines changed

src/ResourceManager/Compute/Commands.Compute/Extension/AzureDiskEncryption/AzureDiskEncryptionExtensionConstants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,6 @@ public static class AzureDiskEncryptionExtensionConstants
3939
public const string osTypeLinux = "Linux";
4040
public const string osTypeWindows = "Windows";
4141
public const string defaultKeyEncryptionAlgorithm = "RSA-OAEP";
42+
public const int httpTimeoutMinutes = 10;
4243
}
4344
}

src/ResourceManager/Compute/Commands.Compute/Extension/AzureDiskEncryption/DisableAzureDiskEncryption.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using System.Collections;
2323
using System.Globalization;
2424
using System.Management.Automation;
25+
using System.Threading.Tasks;
2526

2627
namespace Microsoft.Azure.Commands.Compute.Extension.AzureDiskEncryption
2728
{
@@ -199,10 +200,21 @@ private AzureOperationResponse<VirtualMachine> UpdateVmEncryptionSettings()
199200
Tags = vmParameters.Tags
200201
};
201202

202-
return this.ComputeClient.ComputeManagementClient.VirtualMachines.CreateOrUpdateWithHttpMessagesAsync(
203+
var httpTask = this.ComputeClient.ComputeManagementClient.VirtualMachines.CreateOrUpdateWithHttpMessagesAsync(
203204
this.ResourceGroupName,
204205
vmParameters.Name,
205-
parameters).GetAwaiter().GetResult();
206+
parameters);
207+
208+
if (!httpTask.Wait(new TimeSpan(0, AzureDiskEncryptionExtensionConstants.httpTimeoutMinutes, 0)))
209+
{
210+
string errorMessage = string.Format(CultureInfo.CurrentUICulture, "Extension operation timed out");
211+
ThrowTerminatingError(new ErrorRecord(new ApplicationException(errorMessage),
212+
errorMessage,
213+
ErrorCategory.InvalidResult,
214+
null));
215+
}
216+
217+
return httpTask.Result;
206218
}
207219

208220
public override void ExecuteCmdlet()

src/ResourceManager/Compute/Commands.Compute/Extension/AzureDiskEncryption/GetAzureDiskEncryptionStatus.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,11 +368,20 @@ public override void ExecuteCmdlet()
368368
this.ResourceGroupName, VMName).Body;
369369
VirtualMachineExtension parameters = GetVmExtensionParameters(virtualMachineResponse, osType);
370370

371-
this.VirtualMachineExtensionClient.CreateOrUpdateWithHttpMessagesAsync(
371+
var httpTask = this.VirtualMachineExtensionClient.CreateOrUpdateWithHttpMessagesAsync(
372372
this.ResourceGroupName,
373373
this.VMName,
374374
this.Name,
375-
parameters).GetAwaiter().GetResult();
375+
parameters);
376+
377+
if (!httpTask.Wait(new TimeSpan(0, AzureDiskEncryptionExtensionConstants.httpTimeoutMinutes, 0)))
378+
{
379+
string errorMessage = string.Format(CultureInfo.CurrentUICulture, "Extension operation timed out");
380+
ThrowTerminatingError(new ErrorRecord(new ApplicationException(errorMessage),
381+
errorMessage,
382+
ErrorCategory.InvalidResult,
383+
null));
384+
}
376385

377386
Dictionary<string, string> encryptionStatusParsed = null;
378387
try

src/ResourceManager/Compute/Commands.Compute/Extension/AzureDiskEncryption/SetAzureDiskEncryptionExtension.cs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
using System.Collections;
2424
using System.Globalization;
2525
using System.Management.Automation;
26+
using System.Threading.Tasks;
2627

2728
namespace Microsoft.Azure.Commands.Compute.Extension.AzureDiskEncryption
2829
{
@@ -299,10 +300,21 @@ private AzureOperationResponse<VirtualMachine> UpdateVmEncryptionSettings()
299300
Location = vmParameters.Location,
300301
Tags = vmParameters.Tags
301302
};
302-
return this.ComputeClient.ComputeManagementClient.VirtualMachines.CreateOrUpdateWithHttpMessagesAsync(
303+
var httpTask = this.ComputeClient.ComputeManagementClient.VirtualMachines.CreateOrUpdateWithHttpMessagesAsync(
303304
this.ResourceGroupName,
304305
vmParameters.Name,
305-
parameters).GetAwaiter().GetResult();
306+
parameters);
307+
308+
if (!httpTask.Wait(new TimeSpan(0, AzureDiskEncryptionExtensionConstants.httpTimeoutMinutes, 0)))
309+
{
310+
string errorMessage = string.Format(CultureInfo.CurrentUICulture, "Extension operation timed out");
311+
ThrowTerminatingError(new ErrorRecord(new ApplicationException(errorMessage),
312+
errorMessage,
313+
ErrorCategory.InvalidResult,
314+
null));
315+
}
316+
317+
return httpTask.Result;
306318
}
307319

308320
private Hashtable GetExtensionPublicSettings()
@@ -437,11 +449,20 @@ public override void ExecuteCmdlet()
437449

438450
VirtualMachineExtension parameters = GetVmExtensionParameters(virtualMachineResponse);
439451

440-
this.VirtualMachineExtensionClient.CreateOrUpdateWithHttpMessagesAsync(
452+
var httpTask = this.VirtualMachineExtensionClient.CreateOrUpdateWithHttpMessagesAsync(
441453
this.ResourceGroupName,
442454
this.VMName,
443455
this.Name,
444-
parameters).GetAwaiter().GetResult();
456+
parameters);
457+
458+
if (!httpTask.Wait(new TimeSpan(0, AzureDiskEncryptionExtensionConstants.httpTimeoutMinutes, 0)))
459+
{
460+
string errorMessage = string.Format(CultureInfo.CurrentUICulture, "Extension operation timed out");
461+
ThrowTerminatingError(new ErrorRecord(new ApplicationException(errorMessage),
462+
errorMessage,
463+
ErrorCategory.InvalidResult,
464+
null));
465+
}
445466

446467
var op = UpdateVmEncryptionSettings();
447468
var result = Mapper.Map<PSAzureOperationResponse>(op);

0 commit comments

Comments
 (0)