The only reason the role instance is being recycled (restarted) is because the Run RoleEntryPoint method exits. This usually happens if you:
- Canceled Run () and
- You have an unhandled exception in your program code that will cause Run () to exit
Your role, however, will be recycled, but rather freezes if you enable IntelliTrace logging.
The default template for WebRole does not cancel the Run () method, while leaving the default implementation, which is "Thread.Sleep (-1);". There is no (automatic) event that will trigger automatic replication of the WebRole role. If you do not do something in your RoleEntryPoint, this will lead to the exit of the Run method. This automatic recirculation occurs only with WorkerRole, which implement the Run () method.
UPDATE 1 (as per comment 1)
run-Methoded of a RoleEntryPoint faces an error
Not only an error, but also such an error (i.e., an unhandled exception), which is why the Run () method will exit.
In addition, you cannot simply override Run () in your WebRole because your RoleEntryPoint descendat lives in a different application domain (even in a different process) and then in your web application (therefore, it will not have an idea of your exceptions in application). Read more about the full hosting and IIS process here .
So, for the web role, you only have a web application that is full of IIS 7.0 / 7.5 features that do not know that this IIS is part of the Azure deployment. Global.asax is your place to manage the raw errors of web applications in ASP.NET. Check out this question , the answer to which is a good example for the Application_Error () handler.
You can use the static RequestRecycle method of type RoleEnvironment to manually require role reuse in your Application_Error () method. However, do not recommend this. I do not see good practice restarting the web server due to an application error. You must implement good exception handling and error logging strategies, regularly review your error logs, and take action to avoid critical errors that require a server reboot.
What are your initial intentions? To understand when the Role will automatically be recycled or simulate your application, for example, automatically re-process its role upon error? If this is the last, I suggest you reconsider your business requirements / logic.
UPDATE 2
I cannot speak from the mouth of the Nile, but an “instance failure” is all that can lead to a virtual virtual machine freezing. The instance in Windows Azure is a subscription virtual machine that hosts your application code (read this blog post for a detailed explanation on Hosted Service, Role, Instance). The application runs on a Windows Server-based OS. This is a virtual machine. Everything can happen - from a hardware failure on the host, to a failure of the general software / driver of the guest OS. It does not have to be your code. Therefore, in case something happens that will lead to the failure of one virtual machine - this problem is automatically handled by Windows Azure Fabric. If necessary, your code is automatically deployed to another virtual machine. And this happens automatically. You are not doing anything. Imagine that a hard disk rupture or a memory failure occurs, or the network interface stops responding - these are just a few simple problems that can cause a working VM to crash. This is an instance error.
Failure in the code is something you should take care of. Everything else - the Windows Azure Fabric controller takes care.
UPDATE 3
- What happens to an asp.net application in webrole if an exception occurs and it is not handled? Will the application just hang in an undefined state ("broken") until I look at it, or will it be completed by vm?
This question is completely beyond the scope! What happens to an asp.net application in a shared hosting account? Or when installing IIS in place? Application crash for the user whose actions failed. In the worst case, a recycle pool application. I have never seen an asp.net application hanging. There is no such thing as “asp.net application terminated” or “broken”. If this is a common error caused when the application was launched or the first request, the application will never be online. If this is an error caused by a certain sequence of user actions, the user will see an ugly error message and nothing else (if you do not have a corresponding Application_Error () handler in your Global.asax. I think that there is enough explanation for a question that has nothing to do with Azure .
- Can you come up with a .NET code snippet in my application that could cause the entire web role to crash, or is this not possible with managed code (other than an unknown .NET bug)?
Are you joking? This code will crash your role on the Internet and force recycling:
RoleEnvironment.RequestRecycle()
Accept this question as I don't think something is missing. In addition, he has answers to at least 4 more questions added to the original.
FINAL
There is no such thing as "kill an instance forever."