Jaa


Windows Azure roles stuck in Busy state when startup-task is added

With the introduction of SDK 1.3, developers started using start-up tasks quite a bit and often run into below issue. I thought of blogging the issue/resolution here hoping it would someone who is running into the issue.

Symptoms:

1) Application deployment is successful if startup-task is not included.

2) Startup–task for web/worker role is configured and when application is deployed to cloud, roles are stuck in Busy state or being recycled.

3) Issue only happens when when taskType is set to “Simple” in start-up task.

Cause:

One of the very common reason I have seen is if you do not include “exit /b 0” command at the end of your batch file or cmd file, you would run into the issue.

For example, if you would like to enable ping for web roles running under Azure connect, you would write the following commands in your batch file and add it as startup-task and set its taskType to “Simple”

Echo Enable ICMP
netsh advfirewall firewall add rule name="ICMPv6 echo" dir=in action=allow enable=yes protocol=icmpv6:128,any
exit /b 0

If you forget to include “exit /b 0” (above highlighted line) in your batch file, after the netsh command is executed, execution is pretty much stuck because because when you specify “Simple” as taskType, running of the role instance is blocked until the task finishes and we have not indicated that task has finished.

This is by design behavior since simple call is synchronous call.

Parameters for exit command.

/B specifies to exit the current batch script instead of
CMD.EXE. If executed from outside a batch script, it
will quit CMD.EXE

exitCode specifies a numeric number. if /B is specified, sets
ERRORLEVEL that number. If quitting CMD.EXE, sets the process
exit code with that number.

Resolution:

To resolve the issue always include “exit /b 0” command for simple tasks.

Note: “Simple” is also default if you do not specify any value for taskType.

Overview of Startup Tasks for Roles in Windows Azure
https://msdn.microsoft.com/en-us/library/hh124132.aspx

Key words: Windows Azure, Startup task, Simple, Role, Stuck