Sunday, December 13, 2009

Another common reason for Windows Azure role to stuck in Initializing/Busy/Stopping

There is another common reason that will cause your role to stuck into that loop when you deploy it on Windows Azure. And it is common for Web and Worker Roles.

You will most probably encounter this error if you are using latest Windows Azure Tools (as you should to) and you are creating a new project (rather than upgrading your existing one).

The new project template comes with enabled and started DiagnosticsMonitor. In order for this Monitor to work properly and collect and store data it needs a Windows Azure Storage account. The account configuration is saved as Role Configuration Entry in the .CSCFG file. The default “Connection string” is this one:

    1 <Setting name="DiagnosticsConnectionString" value="UseDevelopmentStorage=true" />

Note the “UseDevelopmentStorage=true” in the value for our DiagnosticsConnectionString. If you just make a “Hello World” Web Role and you upload it to Azure environment, that role will never start. It will go a Initializing/Busy/Stopping/Stopped loop. You need to either stop the DiagnosticsMonitor or change the connection string.

Lest first see how the connection string should look like:

    7       <Setting name="StorageClientAccount"

    8                value="DefaultEndpointsProtocol=[https|http];AccountName=[your_account_name];AccountKey=[your_account_key]" />

In this “Connection string” setting for Diagnostics monitor you need to provide:

  • DefaultEndpointsProtocol – http or https
  • AccountName – your storage account name (endpoints are automatically built up)
  • AccountKey – the authentication key that is generated at Storage management part of the portal.

Without specifying these settings your role will not run on Azure environment.

How about disabling DiagnosticsMonitor? Sure you can do so. If you have a WebRole there will be a single file defining a Class (usually called WebRole.cs) that derives from RoleEntryPoint. This class looks something like this:

   24 public class WebRole : RoleEntryPoint

   25 {

   26     public override bool OnStart()

   27     {

   28         DiagnosticMonitor.Start("DiagnosticsConnectionString");


   30         // For information on handling configuration changes

   31         // see the MSDN topic at

   32         RoleEnvironment.Changing += RoleEnvironmentChanging;

   33         ...

It is important to note line 28, on which there is a call: DiagnosticMonitor.Start("DiagnosticsConnectionString");

If want to remove the DiagnosticsMonitor just strip the entire OnStart() method. However I suggest not to do so, because you will loose all logging functionalities of Windows Azure.

I hope that this eliminates most common reasons for headaches of Windows Azure Role stuck in Initializing/Busy/Stopping/Stopped loops.

Thursday, December 10, 2009

Windows Azure role stuck in Initializing/Busy/Stopping

Recently I see a lot of questions with that description around Windows Azure Forums. There is one particular reason that appears to be causing this behaviour in most of the cases. I want to describe it with respect to Web Role and Worker Role

Web Role

If you have a web role prepared for Windows Azure deployment be sure that you double check that you have set “Copy Local” attribute to TRUE for any third party assemblies that you reference in your project. These are all assemblies that are not part of Microsoft .NET Framework 3.5 SP1. Such as Microsoft ReportViewer, Microsoft MVC, Microsoft WCF RIA Services, Unity, nHibernate, SandCastle. Any.


Worker Role

While requirements for referenced assemblies in Worker roles are same as requirements for these in Web Roles, there is another important point to observe. And this is that your Run() method should never end. If it ends, than Windows Azure Fabric thinks there is something wrong are recycles your role. That’s why you initial Run method will look like this:

    1         public override void Run()

    2         {

    3             // This is a sample worker implementation. Replace with your logic.

    4             Trace.WriteLine("WorkerRole2 entry point called", "Information");


    6             while (true)

    7             {

    8                 Thread.Sleep(10000);

    9                 Trace.WriteLine("Working", "Information");

   10             }

   11         }

It is important to not remove the while (true) cycle as it it the “lifecycle” of our worker role. If we remove it,our worker role will enter an endless loop of:

[runtime] Role entrypoint . COMPLETED OnStart()
[runtime] Role entrypoint . CALLING   Run()
Information: Worker Process entry point called
[runtime] Role entrypoint . COMPLETED Run() ==> ROLE RECYCLING INITIATED
[runtime] Role instance recycling is starting
Information: ...
Information: ...
[fabric] Role state Recycle
[fabric] Role state Stopping
[fabric] Role state Stopped
[fabric] Role state Stopping
[fabric] Role state Stopped
[fabric] Role state Suspended
[fabric] Role state Aborted
[fabric] Role state Teardown
[fabric] Role state Destroyed
[fabric] Role state Created
[fabric] Role state Suspended

Why is it so is well described by Steve Marx as answer to my question on MSDN Forums:

The model is that you're expected to never return from Run().  (If you do, we think something went wrong and restart you.)
If you have other threads doing work, you can just go into an infinite sleep at the bottom of Run().  (Thread.Sleep(Timeout.Infinite))

I really hope that this post will save you lot of time and frustration using Windows Azure.

Tuesday, December 1, 2009

Windows Azure bookmarks

I decided to post a couple of very useful links to resources on Windows Azure, which I happen to use very often and almost always search for them first.

So here there are:

Register on Microsoft Connect to get CTP account (limited)
Note: it is one registration process for both Windows Azure and SQL Azure. However the invitation tokens does not come together and you have to be patient, you will recieve both tokens in couple of business days.

Windows Azure Platform on MSDN


Tools & SDKs

Windows Azure Tools for Visual Studio (NOV'2009)

Windows Azure SDK (NOV'2009)

Microsoft .NET Services SDK (NOV'CTP)

Additional Azure Samples, including ASP.NET Providers for Table Storage

Azure on Channel 9

MSDN Documentation on "Online Services":

SQL Azure Firewall

Azure Platform Forums on MSDN: