Skip to content

Commit

Permalink
Prevent integer-overflow when calculating polling-interval during Azu…
Browse files Browse the repository at this point in the history
…re Resource Group deployments.

Closes OctopusDeploy/Issues#2426
  • Loading branch information
MJRichardson committed Mar 13, 2016
1 parent 375cfe0 commit fa6cdb8
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,16 @@ static void CreateDeployment(ResourceManagementClient armClient, string resource
static void PollForCompletion(IResourceManagementClient armClient, string resourceGroupName,
string deploymentName, VariableDictionary variables)
{
// While the deployment is running, we poll to check it's state.
// We increase the poll interval according to the Fibonacci sequence, up to a maximum of 30 seconds.
var currentPollWait = 1;
var previousPollWait = 0;
var continueToPoll = true;
const int maxWaitSeconds = 30;

while (continueToPoll)
{
Thread.Sleep(TimeSpan.FromSeconds(Math.Min(currentPollWait, 30)));
Thread.Sleep(TimeSpan.FromSeconds(Math.Min(currentPollWait, maxWaitSeconds)));

Log.Verbose("Polling for status of deployment...");
var deployment = armClient.Deployments.Get(resourceGroupName, deploymentName).Deployment;
Expand All @@ -132,9 +135,12 @@ static void PollForCompletion(IResourceManagementClient armClient, string resour
throw new CommandException($"Azure Resource Group deployment {deploymentName} failed:\n" + GetOperationResults(armClient, resourceGroupName, deploymentName));

default:
var temp = previousPollWait;
previousPollWait = currentPollWait;
currentPollWait = temp + currentPollWait;
if (currentPollWait < maxWaitSeconds)
{
var temp = previousPollWait;
previousPollWait = currentPollWait;
currentPollWait = temp + currentPollWait;
}
break;
}
}
Expand Down

0 comments on commit fa6cdb8

Please sign in to comment.