Reputation: 115
I have an Azure cloud services web role that needs to make a call to a REST service when it starts up and then when it shuts down to register the role instance with a proxy server on start and remove it when stopping. I overrode the OnStart() and OnStop() methods to add the calls and it works as expected in all instances except when scaling down. When stopping the cloud service or restarting a role instance, the call to the REST service in the OnStop() method runs and completes successfully. When scaling up, the OnStart() method runs and the call to the REST service registers the new role instance with the proxy. However, when scaling back down it looks like the OnStop() method never runs. I also tried using the RoleEnvironmentStopping event handler since that does not have a time limit but the result was the same. I can't find any detailed documentation from Microsoft on the exact lifecycle of a role instance during the scaling action. When I look at my virtual network, it looks like the role instance has it's ip address removed well before the vm is destroyed. Does it make sense that during scaling, the role instance does not have network access when the OnStop() method is called? Is there somewhere else I can/should be doing this cleanup?
Upvotes: 0
Views: 651
Reputation: 11008
OnStop does get called during scale down operations. Typically when I have seen this sort of issue it is due to the code in OnStop writing logging to diagnostics (ie. Diagnostics.Trace lines), but Windows Azure Diagnostics not having enough time to transfer that diagnostics data to storage before the VM is shut down. This makes it look like OnStop is not being called, but in reality it is just the logs not being put into storage.
There are a few ways to verify this:
Upvotes: 1