I have a Cloud Service classic service (web role) in my Azure account where I set up the autoscale.
Since my instances take some time to restart due to various initialization tasks, I manage the lifecycle with the class RoleEntryPoint and its events.
In ServiceDefinition.csdef I have:
In ServiceDefinition.csdef I defined:
<WebRole name="web" vmsize="Standard_A2_v2">
<Runtime executionContext="elevated">
<EntryPoint>
<NetFxEntryPoint assemblyName="web.dll" targetFrameworkVersion="v4.0" />
</EntryPoint>
</Runtime>
According to the documentation in https://learn.microsoft.com/en-us/azure/cloud-services/cloud-services-role-lifecycle-dotnet
While the OnStart code is executing, the role instance is marked as Busy and no external traffic will be directed to it by the load balancer.
So I used the OnStart event to leave the instance in Busy until the initialization is complete
public override bool OnStart()
{
try
{
if (!init())
{
RoleEnvironment.RequestRecycle();
return false;
}
return base.OnStart();
}
catch (Exception e)
{
logException(e);
}
return false;
}
Everything works (almost) well because occasionally, during the scale up, azure gives access to the instances that are initializing and return an error.
Have any of you experienced the same thing?
Any help is welcome.