Instances of Azure Cloud Service accessible during scale up

dsmwb 6 Reputation points
2020-06-19T23:21:03.773+00:00

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.

Azure Cloud Services
Azure Cloud Services
An Azure platform as a service offer that is used to deploy web and cloud applications.
704 questions
{count} votes

4 answers

Sort by: Most helpful
  1. prmanhas-MSFT 17,906 Reputation points Microsoft Employee
    2020-07-02T13:39:23.607+00:00

    @dsmwb Apologies for the delay in response.

    As per the documentation you posted if onstart returns true, it will release the busy, and if it returns false, it will terminate the process.

    So according to your code, is all the initialization code called in init()?

    Also, when you request restart, it will try to restart the instance, but then right after you call that you return false which will try to kill it. I'm not sure this is causing your issue, but I believe the request restart should be put in the onstop method.

    Hope it was helpful.

    Please 'Accept as answer' if it helped, so that it can help others in the community looking for help on similar topics

    0 comments No comments

  2. mpjl 1 Reputation point
    2020-07-10T23:07:30.857+00:00

    Thanks for your reply

    According to the documentation, requesting a recycle of the instance or returning false does not matter because the system still waits for onstart to be completed.
    Also, I've never seen init() fail, so that piece of code is superfluous. However, init() takes some time to complete.


  3. prmanhas-MSFT 17,906 Reputation points Microsoft Employee
    2020-07-21T09:52:27.8+00:00

    @mpjl-0109 Thank you for your response.

    Definitely we will need to reproduce the issue in order to carry out the investigation further on the cause. Since I don't have the required expertise to answer this query what I will suggest is that whenever you are able to reproduce same issue you can right away open a Support Ticket for same so they can assist you further with this.

    If you don't have the ability to open a technical Support Ticket, you can email me with Subject as "ATTN: Preeti" at AzCommunity@microsoft.com and provide me with your Subscription ID and link to this thread. I can then enable your subscription for one time free support.

    Also, once you get the issue fixed, request you to reply back here on the thread with the resolution steps for the benefit of the community.

    Do let me know if I can be of any further help to you.

    Please 'Accept as answer' if it helped, so that it can help others in the community looking for help on similar topics

    Thanks.

    0 comments No comments

  4. mpjl 1 Reputation point
    2020-07-21T21:30:29.727+00:00

    if I had been able to reproduce the issue, I would have already opened a ticket on the Azure dashboard, here the request was more of an attempt to find other people with the same problem and help each other in an attempt to reproduce the issue

    thanks anyway for your efforts


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.