<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Demystify</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/pratyay/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/pratyay/feed.xml</link>
    <description>Learn to unbox hurdles in technologies</description>
    <lastBuildDate>Tue, 16 Apr 2019 05:25:23 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>RDP not working for my cloud service</title>
      <link>https://docs.microsoft.com/archive/blogs/pratyay/rdp-not-working-for-my-cloud-service</link>
      <pubDate>Thu, 16 Aug 2018 23:25:16 GMT</pubDate>
      <dc:creator><![CDATA[Pratyaydeep Chanda]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/pratyay/?p=1085</guid>
      <description><![CDATA[Today I am going to discuss one of the most common scenario faced by the Azure customers who are...]]></description>
      <content:encoded><![CDATA[Today I am going to discuss one of the most common scenario faced by the Azure customers who are using classic cloud service resource - RDP not working throwing the below error !!

<a href="https://msdnshared.blob.core.windows.net/media/2018/08/Remote-Desktop-Error.png"><img width="829" height="353" class="alignleft size-full wp-image-1105" alt="Remote-Desktop-Error" src="https://msdnshared.blob.core.windows.net/media/2018/08/Remote-Desktop-Error.png" /></a>

&nbsp;

&nbsp;

Sometimes you will not be able to download the RDP file itself and will get this error - "<span style="color: #ff0000"><em>Failed to download the file. Error details: error 400 Bad Request</em></span>".

You may get the above errors for multiple reasons:
<ul>
 	<li>RDP user account or Encryption certificate got expired.</li>
 	<li>TCP Port 3389 for RDP is blocked.</li>
 	<li>RDP extension got disabled.</li>
</ul>
Sometimes while troubleshooting the RDP issues with my customers I have found that resetting the RDP user account expiration date or renewing the encryption certificate doesn't work. In those cases I always follow the below steps which resolves all the RDP issues with 100% certainty. ;-)
<ol>
 	<li>Create a self-signed certificate in .pfx format.</li>
 	<li>Upload the self-signed certificate in cloud service certificate store from the Azure Portal.</li>
 	<li>Delete all the existing RDP extensions if present.</li>
 	<li>Re-enable Remote Desktop for the roles by using the self-signed certificate which you created in the step 1.</li>
</ol>
I have automated all the above four steps using a PowerShell script so that it makes our life much easier. :-) .... Run the below PowerShell script in admin or elevated mode, however please make sure you have <a href="https://docs.microsoft.com/en-us/powershell/azure/servicemanagement/install-azure-ps?view=azuresmps-4.0.0">Azure PowerShell Service Management module</a> installed in your system before running it.

&nbsp;
<h5><span style="color: #ff6600">$SubscriptionId = <span style="color: #800000">"your-subscription-id" <span style="color: #008000"># Subscription Id</span></span>
$CloudServiceName <span style="color: #000000">=</span></span> <span style="color: #800000">"mycloudservice"</span> <span style="color: #008000"># Cloud Service name</span>
<span style="color: #ff6600">$CertPassword</span> = <span style="color: #800000">"CertPassword"</span><span style="color: #008000"> # Password for the self-signed certificate</span>
<span style="color: #ff6600">$CertExportFilePath</span> = <span style="color: #800000">"C:\my-cert-file.pfx"</span> <span style="color: #008000"># Local file path where self-signed certificate will be exported</span>
<span style="color: #ff6600">$RdpUserName</span> = <span style="color: #800000">"RemoteUserName"</span> <span style="color: #008000"># RDP user name</span>
<span style="color: #ff6600">$RdpUserPassw0rd</span> = <span style="color: #800000">"RdpPassword"</span> <span style="color: #008000"># RDP user password</span>
<span style="color: #ff6600">$Slot</span> = <span style="color: #800000">"Production"</span> <span style="color: #008000"># Cloud Service slot</span>
<span style="color: #ff6600">$RdpAccountExpiry</span> = $(<span style="color: #0000ff">Get-Date</span>).AddDays(<span style="color: #ff00ff">365</span>) <span style="color: #008000"># RDP user account expiration DateTime</span></h5>
<h5><span style="color: #008000"># Creating self-signed certificate</span>
<span style="color: #0000ff">Write-Host</span> (<span style="color: #0000ff">Get-Date</span>).ToString() <span style="color: #800000">" : Creating self-signed certificate."</span><span style="color: #333399"> -ForegroundColor</span> <span style="color: #ff00ff">Magenta</span>
<span style="color: #ff6600">$cert</span> = <span style="color: #0000ff">New-SelfSignedCertificate</span><span style="color: #333399"> -DnsName</span> (<span style="color: #ff6600">$CloudServiceName + <span style="color: #800000">".cloudapp.net")</span></span><span style="color: #333399"> -CertStoreLocation</span> <span style="color: #800000">"cert:\LocalMachine\My"</span> <span style="color: #333399">-KeyLength</span> 2048 <span style="color: #333399">-KeySpec</span> <span style="color: #800000">"KeyExchange"</span>
<span style="color: #ff6600">$SecureCertPassword</span> = <span style="color: #0000ff">ConvertTo-SecureString</span> -String <span style="color: #ff6600">$CertPassword</span><span style="color: #333399"> -Force</span> <span style="color: #333399">-AsPlainText</span>
<span style="color: #0000ff">Export-PfxCertificate</span> <span style="color: #333399">-Cert</span> <span style="color: #ff6600">$cert</span> <span style="color: #333399">-FilePath</span> <span style="color: #ff6600">$CertExportFilePath</span> <span style="color: #333399">-Password</span><span style="color: #ff6600"> $SecureCertPassword</span>
<span style="color: #0000ff">Write-Host</span> (<span style="color: #0000ff">Get-Date</span>).ToString() <span style="color: #800000">" : Self-signed certificate created successfully at"</span><span style="color: #ff6600"> $CertExportFilePath</span> <span style="color: #333399">-ForegroundColor</span> <span style="color: #ff00ff">Magenta</span></h5>
<h5><span style="color: #008000"># Login to your Azure account</span>
<span style="color: #0000ff">Write-Host</span> (<span style="color: #0000ff">Get-Date</span>).ToString()<span style="color: #800000"> " : Logging into your Azure account."</span> <span style="color: #333399">-ForegroundColor</span> <span style="color: #ff00ff">Magenta</span>
<span style="color: #0000ff">Add-AzureAccount</span>
<span style="color: #0000ff">Select-AzureSubscription</span> <span style="color: #333399">-SubscriptionId</span> <span style="color: #ff6600">$SubscriptionId</span>
<span style="color: #0000ff">Write-Host</span> (<span style="color: #0000ff">Get-Date</span>).ToString() <span style="color: #800000">" : Logged in successfully."</span> <span style="color: #333399">-ForegroundColor</span> <span style="color: #ff00ff">Magenta</span></h5>
<h5><span style="color: #008000"># Uploading self-signed certificate to the cloud service certificate store</span>
<span style="color: #0000ff">Write-Host</span> (<span style="color: #0000ff">Get-Date</span>).ToString()<span style="color: #800000"> " : Uploading self-signed certificate to the cloud service certificate store."</span> <span style="color: #333399">-ForegroundColor</span> <span style="color: #ff00ff">Magenta</span>
<span style="color: #0000ff">Add-AzureCertificate</span> <span style="color: #333399">-serviceName</span><span style="color: #ff6600"> $CloudServiceName</span> <span style="color: #333399">-certToDeploy</span> <span style="color: #ff6600">$CertExportFilePath</span> <span style="color: #333399">–password</span><span style="color: #ff6600"> $CertPassword</span>
<span style="color: #0000ff">Write-Host</span> (<span style="color: #0000ff">Get-Date</span>).ToString() <span style="color: #800000">" : Self-signed certificate uploaded successfully."</span> <span style="color: #333399">-ForegroundColor</span> <span style="color: #ff00ff">Magenta</span></h5>
<h5><span style="color: #008000"># Delete all the existing RDP extensions for a given cloud service slot</span>
<span style="color: #0000ff">Write-Host</span> (<span style="color: #0000ff">Get-Date</span>).ToString() <span style="color: #800000">" : Deleting all the existing RDP extensions for"</span> <span style="color: #ff6600">$Slot</span> <span style="color: #800000">"slot."</span> <span style="color: #333399">-ForegroundColor</span> <span style="color: #ff00ff">Magenta</span>
<span style="color: #0000ff">Remove-AzureServiceRemoteDesktopExtension</span> <span style="color: #333399">-ServiceName</span><span style="color: #ff6600"> $CloudServiceName</span><span style="color: #333399"> -UninstallConfiguration -Slot</span> <span style="color: #ff6600">$Slot</span>
<span style="color: #0000ff">Write-Host</span> (<span style="color: #0000ff">Get-Date</span>).ToString() <span style="color: #800000">" : Successfully deleted all the existing RDP extensions for"</span> <span style="color: #ff6600">$Slot</span><span style="color: #800000"> "slot."</span> <span style="color: #333399">-ForegroundColor</span> <span style="color: #ff00ff">Magenta</span></h5>
<h5><span style="color: #008000"># Enabling remote desktop extension on specified role(s) or all roles on a cloud service slot</span>
<span style="color: #0000ff">Write-Host</span> (<span style="color: #0000ff">Get-Date</span>).ToString() <span style="color: #800000">" : Enabling remote desktop extension on all the roles."</span> <span style="color: #333399">-ForegroundColor</span> <span style="color: #ff00ff">Magenta</span>
$SecureRdpPassword = <span style="color: #0000ff">ConvertTo-SecureString</span><span style="color: #333399"> -String</span> <span style="color: #ff6600">$RdpUserPassw0rd</span><span style="color: #333399"> -Force -AsPlainText</span>
<span style="color: #ff6600">$Credential</span> = <span style="color: #0000ff">New-Object</span> <span style="color: #ff00ff">System.Management.Automation.PSCredential</span> <span style="color: #ff6600">$RdpUserName<span style="color: #000000">,</span>$SecureRdpPassword</span>
<span style="color: #0000ff">Set-AzureServiceRemoteDesktopExtension</span> <span style="color: #333399">-ServiceName</span> <span style="color: #ff6600">$CloudServiceName</span> <span style="color: #333399">-Credential</span> <span style="color: #ff6600">$Credential</span> <span style="color: #333399">-CertificateThumbprint</span> <span style="color: #ff6600">$cert.</span>Thumbprint <span style="color: #333399">-Expiration</span> <span style="color: #ff6600">$RdpAccountExpiry</span> <span style="color: #333399">-Slot</span> <span style="color: #ff6600">$Slot</span>
<span style="color: #0000ff">Write-Host</span> (<span style="color: #0000ff">Get-Date</span>).ToString() <span style="color: #800000">" : Remote desktop extension applied successfully."</span> <span style="color: #333399">-ForegroundColor</span> <span style="color: #ff00ff">Magenta</span></h5>
&nbsp;

Output of the script will be something like below:

<a href="https://msdnshared.blob.core.windows.net/media/2018/08/RDP-Enable-Script-Output.png"><img width="898" height="677" class="alignleft size-full wp-image-1135" alt="RDP-Enable-Script-Output" src="https://msdnshared.blob.core.windows.net/media/2018/08/RDP-Enable-Script-Output.png" /></a>

&nbsp;

Even after running the above script if you are not able to RDP, then definitely it's a networking issue. Few possible reasons:
<ul>
 	<li>May be the network from where you are trying to RDP is blocking the traffic.</li>
 	<li>There could be some ACL rules configured in your cloud service.</li>
 	<li>Firewall rules configured using startup tasks.</li>
 	<li>If your cloud service is sitting behind an NSG, you may need to create rules that allow traffic on ports <strong>3389</strong> and <strong>20000</strong>. The RemoteForwarder and RemoteAccess agents require that port 20000* is open, which may be blocked if you have an NSG.</li>
</ul>
Most of time I have seen that customer's corporate network blocks the RDP traffic due to security reasons. So the first thing you should check if you are able to reach to RDP ports 3389 and 20000 (if applicable as mentioned above) using <a href="https://docs.microsoft.com/en-us/sysinternals/downloads/psping">PsPing</a> or <a href="https://www.microsoft.com/en-in/download/details.aspx?id=24009">PortQry</a> or <a href="https://blogs.technet.microsoft.com/danielmauser/2015/03/18/tip-installing-telnet-client-via-command-line/">Telnet</a>. You can refer my <a href="https://blogs.msdn.microsoft.com/pratyay/2018/08/14/scenario-6-not-able-to-rdp-to-only-healthmonitor-worker-role-and-getting-an-error-this-computer-cant-connect-to-the-remote-computer/">blog</a> where I have discussed how to troubleshoot RDP issues using various tools like PsPing and Network monitor. If you are not getting any response, try to RDP from a different network, may be home network or mobile hotspot, etc.

&nbsp;

I hope you this blog will help you resolve all the RDP issues related to Azure Cloud Service.

Happy Learning !]]></content:encoded>
    </item>
    <item>
      <title>Scenario 8 : ASP.NET SignalR application is not working in azure cloud service</title>
      <link>https://docs.microsoft.com/archive/blogs/pratyay/scenario-8-asp-net-signalr-application-is-not-working-in-azure-cloud-service</link>
      <pubDate>Wed, 15 Aug 2018 20:04:03 GMT</pubDate>
      <dc:creator><![CDATA[Pratyaydeep Chanda]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/pratyay/?p=1025</guid>
      <description><![CDATA[Referring to my blog on Azure Cloud Service Troubleshooting Series, this is the 8th scenario of the...]]></description>
      <content:encoded><![CDATA[Referring to my blog on <a href="https://blogs.msdn.microsoft.com/pratyay/2018/07/30/cloud-service-troubleshooting-series/">Azure Cloud Service Troubleshooting Series</a>, this is the 8th scenario of the lab. Please make sure you have followed the lab setup instructions for <em><strong>Visitor Tracker </strong></em>application as per <a href="https://github.com/prchanda/visitortracker">this</a>, to recreate the problem.

&nbsp;
<h4><span style="text-decoration: underline;color: #008000"><strong>Symptom</strong></span></h4>
Visitor Tracker is an ASP.NET SignalR application which tracks the number of visitors accessing the website. Each user is given a unique tracking id which is displayed on the browser as the user moves the mouse pointer. As new users keep on visiting the site, the other users will be able to see new tracking ids on their browsers. <span style="color: #800000"><em><strong>Click</strong> </em></span>on the below image to get an idea of the expected output.

<a href="https://msdnshared.blob.core.windows.net/media/2018/08/Visitor-Tracking.gif"><img src="https://msdnshared.blob.core.windows.net/media/2018/08/Visitor-Tracking-1024x359.gif" alt="Visitor-Tracking" class="alignleft size-large wp-image-1035" width="1024" height="359" /></a>

But after few days the application stopped working i.e users are not able to see their tracking ids as well as for the other users on the browser.

&nbsp;
<h4><span style="text-decoration: underline;color: #008000"><strong>Troubleshooting</strong></span></h4>
SignalR uses the WebSocket transport where available, and falls back to older transports (Server Sent Events, Forever Frame (for Internet Explorer only), Ajax long polling) where necessary - This is known as SignalR transport negotiation. Refer <a href="https://docs.microsoft.com/en-us/aspnet/signalr/overview/getting-started/introduction-to-signalr">this</a> article to know more. You can determine what transport your application is using by taking a fiddler or F12 browser trace. Let's see what we can find in F12 developer trace...

<a href="https://msdnshared.blob.core.windows.net/media/2018/08/Transport-Negotiation.png"><img src="https://msdnshared.blob.core.windows.net/media/2018/08/Transport-Negotiation-1024x176.png" alt="Transport-Negotiation" class="alignleft size-large wp-image-1055" width="1024" height="176" /></a>

From the above developer trace, we can see that client tried to connect over number of transports but all of them failed with 404 error. I would like to inspect the server response for the first negotiate request for which we got HTTP 200 response.

<strong>Request URL : </strong>https://cloudservicelabs.cloudapp.net:81/tracker/negotiate?clientProtocol=1.3&amp;_=1534347303083

<span style="text-decoration: underline"><strong>Response</strong></span>
<pre id="jsonOutput" class="nohighlight json"><span style="color: #0000ff"><span class="json-open-bracket">{</span><img class="json-minus" src="https://www.freeformatter.com/3.4.0.1/img/minus.gif" /><span class="json-collapse-1">
<span class="json-indent">   </span><span class="json-property">"Url"</span><span class="json-semi-colon">: </span><span class="json-value">"/tracker"</span><span class="json-comma">,</span>
<span class="json-indent">   </span><span class="json-property">"ConnectionToken"</span><span class="json-semi-colon">: </span><span class="json-value">"w9ppacqBDsP/uF90AZ97VYm6L+PYAz03iQPlEiU0uIwSZwEDXih+XHb0PV/FO9T+/22xmJp+St+tDlDg/cMUy1U9Of382YCNa94RYOOpRmsm8MNofd2eLpPNDFfaXAiM"</span><span class="json-comma">,</span>
<span class="json-indent">   </span><span class="json-property">"ConnectionId"</span><span class="json-semi-colon">: </span><span class="json-value">"4e81868d-dd9e-44ac-9b76-0f04da1f71c9"</span><span class="json-comma">,</span>
<span class="json-indent">   </span><span class="json-property">"KeepAliveTimeout"</span><span class="json-semi-colon">: </span><span class="json-value">20</span><span class="json-comma">,</span>
<span class="json-indent">   </span><span class="json-property">"DisconnectTimeout"</span><span class="json-semi-colon">: </span><span class="json-value">30</span><span class="json-comma">,</span>
<span class="json-indent">   </span><span class="json-property">"ConnectionTimeout"</span><span class="json-semi-colon">: </span><span class="json-value">110</span><span class="json-comma">,</span>
<span class="json-indent">   </span><span style="color: #ff0000"><strong><span class="json-property">"TryWebSockets"</span><span class="json-semi-colon">: </span><span class="json-value">false</span></strong></span><span class="json-comma">,</span>
<span class="json-indent">   </span><span class="json-property">"ProtocolVersion"</span><span class="json-semi-colon">: </span><span class="json-value">"1.3"</span><span class="json-comma">,</span>
<span class="json-indent">   </span><span class="json-property">"TransportConnectTimeout"</span><span class="json-semi-colon">: </span><span class="json-value">5</span><span class="json-comma">,</span>
<span class="json-indent">   </span><span class="json-property">"LongPollDelay"</span><span class="json-semi-colon">: </span><span class="json-value">0</span>
<span class="json-indent"></span></span><span class="json-close-bracket">}</span></span></pre>
From the above network trace it's quite clear that client tried to connect over WebSocket but Server doesn't support it. <span>Also note that for SignalR to use WebSocket, IIS 8 must be used, the server must be Windows Server 2012, or later, and WebSocket must be enabled in IIS. We are using Windows Server 2016 but we need to check if WebSocket is enabled in IIS or not. In order to confirm that I logged in to one of the instance and opened <strong>Add Roles and Features Wizard</strong> from Server Manager. Expanded <strong>Web Server (IIS)</strong> role and found that <strong>WebSocket protocol</strong> was not enabled. :-)</span>

&nbsp;

<a href="https://msdnshared.blob.core.windows.net/media/2018/08/Websocket-Feature.png"><img src="https://msdnshared.blob.core.windows.net/media/2018/08/Websocket-Feature-1024x721.png" alt="Websocket-Feature" class="alignleft size-large wp-image-1065" width="1024" height="721" /></a>

In order to enable WebSocket feature you can use the below DISM command in a startup task, so that when the role starts it installs the WebSocket feature in IIS.
<h5><span style="color: #993366"><strong>%SystemRoot%\system32\DISM.exe /Online /Enable-Feature /FeatureName:IIS-WebSockets</strong></span></h5>
&nbsp;

I hope you have got an idea how to enable WebSocket protocol feature in Azure Cloud Service.

Happy Learning !]]></content:encoded>
    </item>
    <item>
      <title>Scenario 7 : I cannot access my website, although all role instances are in running state</title>
      <link>https://docs.microsoft.com/archive/blogs/pratyay/scenario-7-i-cannot-access-my-website-although-all-role-instances-are-in-running-state</link>
      <pubDate>Wed, 15 Aug 2018 15:19:53 GMT</pubDate>
      <dc:creator><![CDATA[Pratyaydeep Chanda]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/pratyay/?p=985</guid>
      <description><![CDATA[Referring to my blog on Azure Cloud Service Troubleshooting Series, this is the 7th scenario of the...]]></description>
      <content:encoded><![CDATA[Referring to my blog on <a href="https://blogs.msdn.microsoft.com/pratyay/2018/07/30/cloud-service-troubleshooting-series/">Azure Cloud Service Troubleshooting Series</a>, this is the 7th scenario of the lab. Please make sure you have followed the lab setup instructions for <em><strong>Visitor Tracker </strong></em>application as per <a href="https://github.com/prchanda/visitortracker">this</a>, to recreate the problem.

&nbsp;
<h4><span style="text-decoration: underline;color: #008000"><strong>Symptom</strong></span></h4>
Visitor Tracker is an ASP.NET SignalR application which tracks the number of visitors accessing the website. But suddenly for some reason I am unable to access the application over default cloud service url (<a href="https://cloudservicelabs.cloudapp.net/">https://cloudservicelabs.cloudapp.net/</a>) and getting an error on the IE browser stating that - "<span style="color: #ff0000"><em>Can’t reach this page</em></span>", although the role instances are in running state.

<a href="https://msdnshared.blob.core.windows.net/media/2018/08/Tracker-Running.png"><img src="https://msdnshared.blob.core.windows.net/media/2018/08/Tracker-Running-1024x156.png" alt="Running instance" class="alignleft size-large wp-image-995" width="1024" height="156" /></a>

&nbsp;
<h4><span style="text-decoration: underline;color: #008000"><strong>Troubleshooting</strong></span></h4>
When we talk about application and service availability, the first thing that comes to my mind is to check if the input endpoint is responding or not. By default HTTP port 80 is always opened for a cloud service web role, hence I would take help of my best friend <a href="https://docs.microsoft.com/en-us/sysinternals/downloads/psping">PsPing</a> and check if port 80 is open or not.
<h5><span style="color: #0000ff">psping cloudservicelabs.cloudapp.net:80</span></h5>
<h5><span style="color: #000000">PsPing v2.01 - PsPing - ping, latency, bandwidth measurement utility</span>
<span style="color: #000000">Copyright (C) 2012-2014 Mark Russinovich</span>
<span style="color: #000000">Sysinternals - www.sysinternals.com</span></h5>
<h5><span style="color: #0000ff">Invalid destination address:</span>
<span style="color: #0000ff">Host not found.</span></h5>
Hmmmm.. that is something really interesting ! Port 80 is blocked 😲 ?

I always like to confirm a behavior or issue from various perspectives which really helps me in isolating the issue faster. So I am going to run another tool called <a href="https://www.microsoft.com/en-in/download/details.aspx?id=24009">PortQry</a> which you can use to troubleshoot TCP/IP connectivity issues like this one. It comes in both flavors, command line and GUI version as well.
<h5><span style="color: #800000">Starting portqry.exe -n cloudservicelabs.cloudapp.net -e 80 -p TCP ...</span></h5>
<h5><span style="color: #800000">Querying target system called:</span></h5>
<h5><span style="color: #800000">cloudservicelabs.cloudapp.net</span></h5>
<h5><span style="color: #800000">Attempting to resolve name to IP address...</span></h5>
<h5><span style="color: #800000">Name resolved to 40.124.28.4</span></h5>
<h5><span style="color: #800000">querying...</span></h5>
<h5><span style="color: #ff0000">TCP port 80 (http service): FILTERED</span>
<span style="color: #800000">portqry.exe -n cloudservicelabs.cloudapp.net -e 80 -p TCP exits with return code 0x00000002.</span></h5>
&nbsp;

Ahhaa...Portqry.exe reports the status of a TCP/IP port 80 as <em><strong>Filtered</strong> </em>which means it is blocked as per <a href="https://support.microsoft.com/en-us/help/310099/description-of-the-portqry-exe-command-line-utility">this</a> documentation. However I am curious to know how the application responds over localhost, hence I have enabled the RDP for the role and logged into the instance to browse the application locally. When I opened the IIS, interestingly I found that there was a http binding over port 81 and not on default http port 80. Hence the request was not reaching the IIS and subsequently we were getting the error "<span style="color: #ff0000"><em>Can’t reach this page</em></span>", whereas locally the website spawned up as expected.

So...now... I browsed the cloud service url over port 81 - <a href="https://cloudservicelabs.cloudapp.net:81/"><span style="color: #993300">https://cloudservicelabs.cloudapp.net:81/</span></a> but wait... again same error ? How can be this possible ? I did a PsPing again but this time over port 81 and got a timeout error...
<h6><span style="color: #993366">psping cloudservicelabs.cloudapp.net:81</span></h6>
<h6><span style="color: #993366">PsPing v2.01 - PsPing - ping, latency, bandwidth measurement utility</span>
<span style="color: #993366">Copyright (C) 2012-2014 Mark Russinovich</span>
<span style="color: #993366">Sysinternals - www.sysinternals.com</span></h6>
<h6><span style="color: #993366">TCP connect to 40.124.28.4:81:</span>
<span style="color: #993366">5 iterations (warmup 1) connecting test:</span>
<span style="color: #0000ff">Connecting to 40.124.28.4:81 (warmup): This operation returned because the timeout period expired.</span>
<span style="color: #0000ff">Connecting to 40.124.28.4:81: This operation returned because the timeout period expired.</span>
<span style="color: #0000ff">Connecting to 40.124.28.4:81: This operation returned because the timeout period expired.</span>
<span style="color: #0000ff">Connecting to 40.124.28.4:81: This operation returned because the timeout period expired.</span>
<span style="color: #0000ff">Connecting to 40.124.28.4:81: This operation returned because the timeout period expired.</span></h6>
<h6><span style="color: #993366">TCP connect statistics for 40.124.28.4:81:</span>
<span style="color: #0000ff">Sent = 4, Received = 0, Lost = 4 (100% loss),</span>
<span style="color: #993366">Minimum = 0.00ms, Maximum = 0.00ms, Average = 0.00ms</span></h6>
It seems like the client request is not reaching the server. In these kind of situations, I always recommend my customers to collect simultaneous network trace from client and server to get a holistic picture. From the server side, I couldn't see any request reaching from my client machine, however from client side trace I could see that client tried to send SYN packets thrice as per TCP handshake sequence but server didn't acknowledged it.

<a href="https://msdnshared.blob.core.windows.net/media/2018/08/ACL-blocking.png"><img src="https://msdnshared.blob.core.windows.net/media/2018/08/ACL-blocking-1024x59.png" alt="ACL-blocking" class="alignleft size-large wp-image-1015" width="1024" height="59" /></a>

The above network trace gave me a hint that request is getting blocked. Now the question is who is blocking it and how ? May be firewall or ACL ? Out of curiosity, I checked the ServiceConfiguration.cscfg file of the cloud service solution and found that, indeed, there is an ACL rule which is blocking the traffic. :-)
<h5><span style="color: #333399">&lt;NetworkConfiguration&gt;</span>
<span style="color: #333399">&lt;AccessControls&gt;</span>
<span style="color: #333399">&lt;AccessControl name="ACS"&gt;</span>
<span style="color: #800000">&lt;Rule action="deny" description="ACS" order="100" remoteSubnet="0.0.0.0/0" /&gt;</span>
<span style="color: #333399">&lt;/AccessControl&gt;</span>
<span style="color: #333399">&lt;/AccessControls&gt;</span>
<span style="color: #333399">&lt;EndpointAcls&gt;</span>
<span style="color: #800000">&lt;EndpointAcl role="Tracker" endPoint="Endpoint1" accessControl="ACS" /&gt;</span>
<span style="color: #333399">&lt;/EndpointAcls&gt;</span>
<span style="color: #333399">&lt;/NetworkConfiguration&gt;</span></h5>
&nbsp;

In order to resolve the issue for now, I have removed the ACL rule and page came up as expected !

I hope you have got an idea how to troubleshoot connectivity and networking issues in Azure Cloud Service.

Happy Learning !]]></content:encoded>
    </item>
    <item>
      <title>Scenario 6 : Not able to RDP to only 'HealthMonitor' worker role instance and getting an error : This computer can't connect to the remote computer</title>
      <link>https://docs.microsoft.com/archive/blogs/pratyay/scenario-6-not-able-to-rdp-to-only-healthmonitor-worker-role-and-getting-an-error-this-computer-cant-connect-to-the-remote-computer</link>
      <pubDate>Tue, 14 Aug 2018 23:37:01 GMT</pubDate>
      <dc:creator><![CDATA[Pratyaydeep Chanda]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/pratyay/?p=915</guid>
      <description><![CDATA[Referring to my blog on Azure Cloud Service Troubleshooting Series, this is the 6th scenario of the...]]></description>
      <content:encoded><![CDATA[Referring to my blog on <a href="https://blogs.msdn.microsoft.com/pratyay/2018/07/30/cloud-service-troubleshooting-series/">Azure Cloud Service Troubleshooting Series</a>, this is the 6th scenario of the lab. Please make sure you have followed the lab setup instructions for <em><strong>Super Convertor </strong></em>application as per <a href="https://github.com/prchanda/superconvertor">this</a>, to recreate the problem.

&nbsp;
<h4><span style="text-decoration: underline;color: #008000"><strong>Symptom</strong></span></h4>
As per the lab instructions I have enabled the RDP for all the cloud service roles, but for some reason Remote Desktop connection is failing <em>only</em> for 'HealthMonitor' worker role instance throwing the below error. Whereas RDP works as expected for the other cloud service role instances.<strong></strong>

<a href="https://msdnshared.blob.core.windows.net/media/2018/08/RDP-Error.png"><img src="https://msdnshared.blob.core.windows.net/media/2018/08/RDP-Error-1024x296.png" alt="RDP Error" class="alignleft size-large wp-image-925" width="1024" height="296" /></a>

&nbsp;
<h4><span style="text-decoration: underline;color: #008000"><strong>Troubleshooting</strong></span></h4>
Remote Desktop Protocol is encapsulated and encrypted within TCP. By default, server listens on TCP port 3389 for RDP connection. Hence I will begin my troubleshooting by first checking whether TCP port 3389 is open or not. I am going to use one of my favorite tool <a href="https://docs.microsoft.com/en-us/sysinternals/downloads/psping">PsPing</a> for checking the connectivity to the port 3389 for my cloud service hostname, you can use <a href="https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/telnet">telnet</a> as well.

&nbsp;
<h5><span style="color: #0000ff">psping.exe cloudservicelabs.cloudapp.net:3389</span></h5>
<h5>PsPing v2.01 - PsPing - ping, latency, bandwidth measurement utility
Copyright (C) 2012-2014 Mark Russinovich
Sysinternals - www.sysinternals.com</h5>
<h5>TCP connect to 40.124.28.4:3389:
5 iterations (warmup 1) connecting test:
<span style="color: #0000ff">Connecting to 40.124.28.4:3389 (warmup): 281.25ms</span>
<span style="color: #0000ff">Connecting to 40.124.28.4:3389: 279.08ms</span>
<span style="color: #0000ff">Connecting to 40.124.28.4:3389: 283.01ms</span>
<span style="color: #0000ff">Connecting to 40.124.28.4:3389: 269.29ms</span>
<span style="color: #0000ff">Connecting to 40.124.28.4:3389: 270.12ms</span></h5>
<h5>TCP connect statistics for 40.124.28.4:3389:
<span style="color: #0000ff">Sent = 4, Received = 4, Lost = 0 (0% loss)</span>,
Minimum = 269.29ms, Maximum = 283.01ms, Average = 275.37ms</h5>
&nbsp;

As per the above statistics, definitely RDP port is open and server is responding as expected to TCP ping over port 3389. That's strange ! Few questions came to my mind...
<ul>
 	<li>Why the server is not responding to RDP connection request even if the port 3389 is open ?</li>
 	<li>Are there any <a href="https://blogs.msdn.microsoft.com/walterm/2014/04/22/windows-azure-paas-acls-are-here/">Access Control Lists</a> defined for the cloud service ?</li>
 	<li>Is there any <a href="https://docs.microsoft.com/en-us/azure/cloud-services/cloud-services-startup-tasks-common#add-firewall-rules">windows firewall rule configured using startup task</a> ?</li>
</ul>
Checked the ServiceDefinition.csdef file but couldn't find any ACL configured and there were no startup tasks related to firewall configuration for this cloud service solution as well. The only thing that was left was to capture a <a href="https://www.microsoft.com/en-us/download/4865">Network Monitor</a> trace and analyze the RDP traffic. Without any second thought I started collecting network trace from my client machine while replicating the issue and this is what I can see.

<a href="https://msdnshared.blob.core.windows.net/media/2018/08/RDP-Trace.png"><img src="https://msdnshared.blob.core.windows.net/media/2018/08/RDP-Trace-1024x163.png" alt="RDP-Trace" class="alignleft size-large wp-image-955" width="1024" height="163" /></a>

&nbsp;

Let's split the above network trace screenshot into two halves for better understanding. Every TCP session is always established with the three way handshake, which depicted by the first half of the screenshot.

<a href="https://msdnshared.blob.core.windows.net/media/2018/08/RDP-TCP-handshake.png"><img src="https://msdnshared.blob.core.windows.net/media/2018/08/RDP-TCP-handshake-1024x55.png" alt="RDP-TCP-handshake" class="alignleft size-large wp-image-965" width="1024" height="55" /></a>

&nbsp;

The first three frames (90, 97 and 98) with the Syn , Syn/Ack and Ack flags depicted as S, A..S, and A respectively is what is collectively referred to as the TCP three way handshake, which is successful in our case. Moving on to the later half of the network trace I can see that client has initiated a RDP connection request depicted by <strong>X224: Connection Request </strong>but didn't receive any confirmation from the server side as per <a href="https://msdn.microsoft.com/en-us/library/cc240452.aspx">RDP connection sequence</a>. The X.224 Connection Request PDU is an RDP Connection Sequence PDU sent from client to server during the Connection Initiation phase of the RDP Connection Sequence (section <a href="https://msdn.microsoft.com/en-us/library/cc240452.aspx">1.3.1.1</a> for an overview of the RDP Connection Sequence phases).

Instead server tore down the TCP session with a Fin flag (depicted as A…F in frame number 491). The client in turn acknowledges the server’s packet and then proceeds to abruptly terminate the session with the Reset flag (depicted as A.R..) in the screenshot below, also acknowledging the receipt of the previous pact from the server (thus the A in A.R..).

<a href="https://msdnshared.blob.core.windows.net/media/2018/08/RDP-failure.png"><img src="https://msdnshared.blob.core.windows.net/media/2018/08/RDP-failure-1024x64.png" alt="RDP-failure" class="alignleft size-large wp-image-975" width="1024" height="64" /></a>

&nbsp;

This looks like a firewall issue as the server is gracefully terminating the RDP connection request after TCP handshake is complete. But where or how exactly firewall rules are configured ?

Upon reviewing the WorkerRole.cs of 'HealthMonitor' role, I found that firewall rules were programmatically added using <a href="https://docs.microsoft.com/en-us/previous-versions/windows/desktop/api/netfw/nn-netfw-inetfwrules">INetFwRules interface</a> :-) So point to be kept in mind that firewall rules can be added not only through startup tasks or ACL but also through application code.

&nbsp;
<h6><span style="color: #993366">Type Policy2 = Type.GetTypeFromProgID("HNetCfg.FwPolicy2", false);</span>
<span style="color: #993366">INetFwPolicy2 FwPolicy = (INetFwPolicy2)Activator.CreateInstance(Policy2);</span>
<span style="color: #993366">INetFwRules rules = FwPolicy.Rules;</span>
<span style="color: #993366">rules.Remove("Magic Rule");</span></h6>
<h6><span style="color: #993366">Type RuleType = Type.GetTypeFromProgID("HNetCfg.FWRule");</span>
<span style="color: #993366">INetFwRule rule = (INetFwRule)Activator.CreateInstance(RuleType);</span>
<span style="color: #993366">rule.Name = "Magic Rule";</span>
<span style="color: #993366">rule.Protocol = 6;</span>
<span style="color: #993366">rule.LocalPorts = "3389";</span>
<span style="color: #993366">rule.Action = NET_FW_ACTION_.NET_FW_ACTION_BLOCK;</span>
<span style="color: #993366">rule.Direction = NET_FW_RULE_DIRECTION_.NET_FW_RULE_DIR_IN;</span>
<span style="color: #993366">rule.Enabled = true;</span>
<span style="color: #993366">rules.Add(rule);</span></h6>
&nbsp;

I hope you have got an idea how to troubleshoot RDP issues in Azure Cloud Service.

Happy Learning !]]></content:encoded>
    </item>
    <item>
      <title>Scenario 5 : My website is throwing HTTP Error 503. The service is unavailable when browsed over the default cloud service domain url (*.cloudapp.net)</title>
      <link>https://docs.microsoft.com/archive/blogs/pratyay/scenario-5-my-website-is-throwing-http-error-503-the-service-is-unavailable-when-browsed-over-the-default-cloud-service-domain-url-cloudapp-net</link>
      <pubDate>Mon, 13 Aug 2018 12:18:27 GMT</pubDate>
      <dc:creator><![CDATA[Pratyaydeep Chanda]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/pratyay/?p=895</guid>
      <description><![CDATA[Referring to my blog on Azure Cloud Service Troubleshooting Series, this is the 5th scenario of the...]]></description>
      <content:encoded><![CDATA[Referring to my blog on <a href="https://blogs.msdn.microsoft.com/pratyay/2018/07/30/cloud-service-troubleshooting-series/">Azure Cloud Service Troubleshooting Series</a>, this is the 5th scenario of the lab. Please make sure you have followed the lab setup instructions for <em><strong>Super Convertor </strong></em>application as per <a href="https://github.com/prchanda/superconvertor">this</a>, to recreate the problem.

&nbsp;
<h4><span style="text-decoration: underline"><span style="color: #008000"><strong>Symptom</strong></span></span></h4>
I am getting <span style="color: #ff0000"><strong>HTTP Error 503</strong></span> response while browsing my cloud service application url (https://cloudservicelabs.cloudapp.net/), although my web role 'SuperConvertor' is in running state. Rebooting or Re-imaging the role instance is not resolving the issue.
<h2><strong>Service Unavailable</strong></h2>

<hr />

<strong>HTTP Error 503. The service is unavailable.</strong>

&nbsp;
<h4><span style="text-decoration: underline;color: #008000"><strong>Troubleshooting</strong></span></h4>
Usually when you get 50x errors in your application, it means something is broken at the server side. <code><strong>503 Service Unavailable</strong></code> server error response code indicates that the server is not ready to handle the request. You must be thinking why suddenly a newly deployed cloud service application suddenly started throwing this error. Is the application crashing ? Is the request reaching the IIS server ? Is the server under high load ?

Generally when I am confused with all of these questions, I follow the basic troubleshooting as I would have done while dealing with an On-Prem IIS server. So I RDP to the web role instance and browse the application locally. Before browsing the site locally, out of curiosity I checked the Application and System event viewer logs to negate any possibility of IIS ApplicationPool crash  or any other application related exceptions. It was absolutely clear !

Next I checked the IIS logs present under <strong>C:\Resources\directory\{Deployment ID}.SuperConvertor.DiagnosticStore\LogFiles\Web </strong>to check if we can get more information about the HTTP 503 error like sub-status code, time taken to execute the request, etc. It came to my surprise that the directory is absolutely empty, no IIS log has been generated so far !

This means the request is not reaching to the IIS at all. As per IIS architecture, we know that HTTP.sys listens for HTTP requests from the network, passes the requests onto IIS for processing, and then returns processed responses to client browsers. By default, IIS provides HTTP.sys as the protocol listener that listens for HTTP and HTTPS requests and any error at HTTP.sys level is logged in this directory - <strong>D:\Windows\System32\LogFiles\HTTPERR</strong>. So let's see what we can find in HTTPErr log -
<div id="htmlOutputWrapper">
<pre id="htmlOutput" class="html"><code class="hljs xml">#Software: Microsoft HTTP API 2.0
#Version: 1.0
#Date: 2018-08-13 03:12:38
#Fields: date time c-ip c-port s-ip s-port cs-version cs-method cs-uri streamid sc-status s-siteid s-reason s-queuename
2018-08-13 03:25:22 293.217.138.127 12052 10.1.2.5 80 HTTP/1.1 GET / - 503 - N/A -
2018-08-13 03:25:22 293.217.138.127 20463 10.1.2.5 80 HTTP/1.1 GET /favicon.ico - 503 - N/A -
</code></pre>
&nbsp;

Clearly if you see the above log, HTTP 503 is thrown from HTTP.sys level and the client request is getting rejected from there itself without reaching the IIS. Now we are going to browse the site locally from IIS and see what happens - I get an error - <span style="color: #ff0000"><em>This page can’t be displayed<span style="color: #000000">.</span></em><span style="color: #000000"> One thing I noticed is that the IIS website was having a binding like below, which means in order to access this particular website we need to access over the custom domain name (<span style="color: #0000ff">www.cloudservicelabs.com</span>)</span><em><span style="color: #000000">
</span></em></span>
<table width="659" cellspacing="0" cellpadding="2" border="0">
<tbody>
<tr>
<td style="text-align: center" width="87" valign="top"><strong>IP Address</strong></td>
<td style="text-align: center" width="53" valign="top"><strong>Port</strong></td>
<td style="text-align: center" width="165" valign="top"><strong>Host Header</strong></td>
</tr>
<tr>
<td style="text-align: center" width="87" valign="top"><strong>10.1.2.5</strong></td>
<td style="text-align: center" width="53" valign="top"><strong>80</strong></td>
<td style="text-align: center" width="165" valign="top"><strong>www.cloudservicelabs.com</strong></td>
</tr>
</tbody>
</table>
<span style="color: #ff0000"><em><span style="color: #000000"><span>
</span></span></em><span style="color: #000000">Websites are accessed by every client using bindings.</span><span style="color: #000000"> A typical binding for Websites is in the form of IP:Port:HostHeader. It is a mechanism which tells the server how this site can be reached. The next question that will come to your mind is that from where does this custom hostname came from ?
</span></span>

ServiceDefinition.csdef is the place where you can configure the bindings for your webrole, and here is what I can see for this application:
<h5>&lt;WebRole name="SuperConvertor" vmsize="Standard_D1_v2"&gt;
&lt;Sites&gt;
&lt;Site name="Web"&gt;
&lt;Bindings&gt;
<span style="color: #0000ff">&lt;Binding name="Endpoint1" endpointName="Endpoint1" hostHeader="www.cloudservicelabs.com"/&gt;</span>
&lt;/Bindings&gt;
&lt;/Site&gt;
&lt;/Sites&gt;</h5>
</div>
&nbsp;

In real world scenario, in order to access your cloud service application over a custom hostname, you need to have a DNS configured for this host header corresponding to the cloud service VIP. For now, you can delete the <strong>hostHeader</strong> attribute from <strong>Binding</strong> element and redeploy your cloud service solution to resolve the issue.

&nbsp;

I hope you have got an idea how to troubleshoot issues related application accessibility in Azure Cloud Service.

Happy Learning !]]></content:encoded>
    </item>
    <item>
      <title>Scenario 4 : ProcessorEngine role is stuck in Busy state stating - Preparing to start role... System is initializing</title>
      <link>https://docs.microsoft.com/archive/blogs/pratyay/scenario-4-processorengine-role-is-stuck-in-busy-state-stating-preparing-to-start-role-system-is-initializing</link>
      <pubDate>Mon, 13 Aug 2018 10:02:10 GMT</pubDate>
      <dc:creator><![CDATA[Pratyaydeep Chanda]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/pratyay/?p=845</guid>
      <description><![CDATA[Referring to my blog on Azure Cloud Service Troubleshooting Series, this is the 4th scenario of the...]]></description>
      <content:encoded><![CDATA[Referring to my blog on <a href="https://blogs.msdn.microsoft.com/pratyay/2018/07/30/cloud-service-troubleshooting-series/">Azure Cloud Service Troubleshooting Series</a>, this is the 4th scenario of the lab. Please make sure you have followed the lab setup instructions for <em><strong>Super Convertor </strong></em>application as per <a href="https://github.com/prchanda/superconvertor">this</a>, to recreate the problem.

&nbsp;
<h4><span style="text-decoration: underline;color: #008000"><strong>Symptom</strong></span></h4>
While deploying the cloud service application to azure we find that ProcessorEngine role is stuck in Busy state and never comes out of it. The azure portal blade shows a message - <em>Preparing to start role... System is initializing</em>.

&nbsp;
<h4><span style="text-decoration: underline"><span style="color: #008000;text-decoration: underline"><strong>Troubleshooting</strong></span></span></h4>
If a role is stuck in <strong>Busy</strong> state, it indicates that there is something wrong with the application that is keeping the role instance from running. Check your application code to see if the <a href="https://msdn.microsoft.com/library/microsoft.windowsazure.serviceruntime.roleenvironment.statuscheck">StatusCheck</a> event is handled and as per <a href="https://blogs.msdn.microsoft.com/kwill/2011/05/05/windows-azure-role-architecture/">Windows Azure Role Architecture</a> <strong>WaHostBootstrapper</strong> process is responsible for:
<ol>
 	<li><span style="color: #0000ff">Reading the role configuration and starting up all of the appropriate tasks and processes to configure and run the role.</span></li>
 	<li><span style="color: #0000ff">Monitoring all of its child processes.</span></li>
 	<li><span style="color: #0000ff">Raising the StatusCheck event on the role host process.</span></li>
</ol>
So the best place to start the troubleshooting is to RDP to the instance and inspect <strong>WaHostBootstrapper.log</strong> file present under the path <strong>C:\Resources</strong>. Upon checking the folder I found that there is only one log file which means that WaHostBootstrapper has only tried to start one time and it isn’t recycling due to an error. Let's see what's inside the <strong>WaHostBootstrapper.log</strong> file:

&nbsp;
<div id="htmlOutputWrapper">
<pre id="htmlOutput" class="html"><code class="hljs xml"><span style="color: #993366">[00003604:00002604, 2018/08/13, 03:08:21.214, ERROR] <span class="hljs-tag">&lt;<span class="hljs-name">-</span> <span class="hljs-attr">WapXmlReadRoleModel</span>=<span class="hljs-string">0x1</span>
[<span class="hljs-attr">00003604:00002604</span>, <span class="hljs-attr">2018</span>/<span class="hljs-attr">08</span>/<span class="hljs-attr">13</span>, <span class="hljs-attr">03:08:21.979</span>, <span class="hljs-attr">ERROR</span>] &lt;<span class="hljs-attr">-</span> <span class="hljs-attr">WapXmlReadContainerId</span>=<span class="hljs-string">0x1</span>
[<span class="hljs-attr">00003604:00002604</span>, <span class="hljs-attr">2018</span>/<span class="hljs-attr">08</span>/<span class="hljs-attr">13</span>, <span class="hljs-attr">03:08:22.026</span>, <span class="hljs-attr">ERROR</span>] &lt;<span class="hljs-attr">-</span> <span class="hljs-attr">WapGetVirtualAccountName</span>=<span class="hljs-string">0x1</span>
[<span class="hljs-attr">00003604:00002604</span>, <span class="hljs-attr">2018</span>/<span class="hljs-attr">08</span>/<span class="hljs-attr">13</span>, <span class="hljs-attr">03:08:22.026</span>, <span class="hljs-attr">ERROR</span>] &lt;<span class="hljs-attr">-</span> <span class="hljs-attr">WapGetAppCmdPath</span>=<span class="hljs-string">0x1</span>
[<span class="hljs-attr">00003604:00002604</span>, <span class="hljs-attr">2018</span>/<span class="hljs-attr">08</span>/<span class="hljs-attr">13</span>, <span class="hljs-attr">03:08:22.026</span>, <span class="hljs-attr">ERROR</span>] &lt;<span class="hljs-attr">-</span> <span class="hljs-attr">WapSetDefaultEnvironment</span>=<span class="hljs-string">0x1</span>
[<span class="hljs-attr">00003604:00002604</span>, <span class="hljs-attr">2018</span>/<span class="hljs-attr">08</span>/<span class="hljs-attr">13</span>, <span class="hljs-attr">03:08:22.014</span>, <span class="hljs-attr">ERROR</span>] &lt;<span class="hljs-attr">-</span> <span class="hljs-attr">WapGetAppHostConfigPath</span>=<span class="hljs-string">0x1</span>
[<span class="hljs-attr">00003604:00002604</span>, <span class="hljs-attr">2018</span>/<span class="hljs-attr">08</span>/<span class="hljs-attr">13</span>, <span class="hljs-attr">03:08:22.045</span>, <span class="hljs-attr">ERROR</span>] &lt;<span class="hljs-attr">-</span> <span class="hljs-attr">GetDebugger</span>=<span class="hljs-string">0x1</span>
[<span class="hljs-attr">00003604:00002604</span>, <span class="hljs-attr">2018</span>/<span class="hljs-attr">08</span>/<span class="hljs-attr">13</span>, <span class="hljs-attr">03:08:22.092</span>, <span class="hljs-attr">ERROR</span>] &lt;<span class="hljs-attr">-</span> <span class="hljs-attr">GetStartupTaskDebugger</span>=<span class="hljs-string">0x1</span>
[<span class="hljs-attr">00003604:00002604</span>, <span class="hljs-attr">2018</span>/<span class="hljs-attr">08</span>/<span class="hljs-attr">13</span>, <span class="hljs-attr">03:08:22.389</span>, <span class="hljs-attr">ERROR</span>] &lt;<span class="hljs-attr">-</span> <span class="hljs-attr">WapGetEnvironmentVariable</span>=<span class="hljs-string">0x800700cb</span>
<strong>[<span class="hljs-attr">00003604:00002604</span>, <span class="hljs-attr">2018</span>/<span class="hljs-attr">08</span>/<span class="hljs-attr">13</span>, <span class="hljs-attr">03:08:22.405</span>, <span class="hljs-attr">WARN</span> ] <span class="hljs-attr">Executing</span> <span class="hljs-attr">Startup</span> <span class="hljs-attr">Task</span> <span class="hljs-attr">type</span>=<span class="hljs-string">0</span> <span class="hljs-attr">rolemodule</span>=<span class="hljs-string">(null)</span> <span class="hljs-attr">cmd</span>=<span class="hljs-string">"E:\approot\.\startup.cmd"</span>
[<span class="hljs-attr">00003604:00002604</span>, <span class="hljs-attr">2018</span>/<span class="hljs-attr">08</span>/<span class="hljs-attr">13</span>, <span class="hljs-attr">03:08:22.405</span>, <span class="hljs-attr">WARN</span> ] <span class="hljs-attr">Executing</span> "<span class="hljs-attr">E:</span>\<span class="hljs-attr">approot</span>\<span class="hljs-attr">.</span>\<span class="hljs-attr">startup.cmd</span>" <span class="hljs-attr">.</span></strong></span></span></code></pre>
</div>
From the above log it looks like the process is stuck while running a startup script named 'startup.cmd' present under E:\approot directory. If I compare the timestamp of the last entry (<code class="hljs xml"><span><span class="hljs-tag"><strong><span class="hljs-attr">2018</span>/<span class="hljs-attr">08</span>/<span class="hljs-attr">13</span>, <span class="hljs-attr">03:08:22.405</span></strong></span></span></code>) with that of current system time (<code class="hljs xml"><span><span class="hljs-tag"><strong><span class="hljs-attr">2018</span>/<span class="hljs-attr">08</span>/<span class="hljs-attr">13</span>, <span class="hljs-attr">04:16:13.132</span></strong></span></span></code>), I see that the host bootstrapper process has been trying to run the startup script for more than an hour. An interesting point to be noted is that, <code class="hljs xml"><span><span class="hljs-tag"><strong><span class="hljs-attr">Startup</span> <span class="hljs-attr">Task</span> <span class="hljs-attr">type</span>=<span class="hljs-string">0</span></strong></span></span></code> which means it is a simple startup task which causes the system to wait for the task to exit before continuing execution. Refer <a href="https://docs.microsoft.com/en-us/azure/cloud-services/cloud-services-startup-tasks">this</a> link to know more about startup task type.

&nbsp;

Windows Azure Bootstrapper eventviewer log shows the same piece of information:

<a href="https://msdnshared.blob.core.windows.net/media/2018/08/WaHostBootstrapper.png"><img src="https://msdnshared.blob.core.windows.net/media/2018/08/WaHostBootstrapper-1024x513.png" alt="WaHostBootstrapper Eventviewer" class="alignleft size-large wp-image-855" width="1024" height="513" /></a>

&nbsp;

Hence the next obvious step to check the functionality of this startup script. So...the script is running an executable 'setup.exe' which takes a command line 'configuration.xml'. The output of the script processing is logged in 'StartupLog.txt' file created under RoleTemp directory.

&nbsp;
<h6><span style="color: #0000ff">REM If WINWORD.EXE and EXCEL.EXE exists, then required office binaries are already installed.</span>
<span style="color: #0000ff">IF "%ComputeEmulatorRunning%" == "true" (</span>
<span style="color: #0000ff">GOTO Finish</span>
<span style="color: #0000ff">)ELSE (</span>
<span style="color: #0000ff">IF EXIST "D:\Program Files (x86)\Microsoft Office\root\Office16\WINWORD.EXE" (</span>
<span style="color: #0000ff">ECHO Startup has already configured and installed required word processing binaries. Exiting. &gt;&gt; "%TEMP%\StartupLog.txt" 2&gt;&amp;1</span>
<span style="color: #0000ff">GOTO Finish</span>
<span style="color: #0000ff">)</span>
<span style="color: #0000ff">IF EXIST "D:\Program Files (x86)\Microsoft Office\root\Office16\EXCEL.EXE" (</span>
<span style="color: #0000ff">ECHO Startup has already configured and installed required excel processing binaries. Exiting. &gt;&gt; "%TEMP%\StartupLog.txt" 2&gt;&amp;1</span>
<span style="color: #0000ff">GOTO Finish</span>
<span style="color: #0000ff">)</span></h6>
<h6><span style="color: #0000ff">REM Run your real exe task</span>
<span style="color: #0000ff">ECHO Running setup.exe &gt;&gt; "%TEMP%\StartupLog.txt" 2&gt;&amp;1</span>
<span style="color: #ff0000">start /wait %~dp0setup.exe /configure %~dp0configuration.xml &gt;&gt; %TEMP%\StartupLog.txt 2&gt;&gt;&amp;1</span>
<span style="color: #0000ff">ECHO Creating Desktop directory &gt;&gt; "%TEMP%\StartupLog.txt" 2&gt;&amp;1</span>
<span style="color: #0000ff">MKDIR "D:\Windows\System32\config\systemprofile\Desktop"</span></h6>
<h6><span style="color: #0000ff">IF %ERRORLEVEL% EQU 0 (</span>
<span style="color: #0000ff">REM The application installed without error.</span></h6>
<h6><span style="color: #0000ff">ECHO The application installed without error. &gt; "%RoleRoot%\Success.txt"</span></h6>
<h6><span style="color: #0000ff">) ELSE (</span>
<span style="color: #0000ff">REM An error occurred. Log the error and exit with the error code.</span></h6>
<h6><span style="color: #0000ff">DATE /T &gt;&gt; "%TEMP%\StartupLog.txt" 2&gt;&amp;1</span>
<span style="color: #0000ff">TIME /T &gt;&gt; "%TEMP%\StartupLog.txt" 2&gt;&amp;1</span>
<span style="color: #0000ff">ECHO An error occurred running the setup. Errorlevel = %ERRORLEVEL%. &gt;&gt; "%TEMP%\StartupLog.txt" 2&gt;&amp;1</span></h6>
<h6><span style="color: #0000ff">EXIT %ERRORLEVEL%</span>
<span style="color: #0000ff">)</span>
<span style="color: #0000ff">)</span>
<span style="color: #0000ff">:Finish</span></h6>
<h6><span style="color: #0000ff">REM Exit normally.</span>
<span style="color: #0000ff">EXIT /B 0</span></h6>
&nbsp;

Let's navigate to the path <strong>C:\Resources\temp\{Deployment ID}.ProcessorEngine\RoleTemp </strong>and analyze the log file 'StartupLog.txt'. Basically it says - "<strong><span style="color: #339966"><em>Running setup.exe</em></span></strong>" which means the script has not completed execution of setup.exe, it's still running. In this kind of situation, I usually further isolate the issue by running the wrapped executable as a standalone script. While I was about to run the executable from command prompt I figured out that 'configuration.xml' is missing from E:\approot location and hence it was leading to startup task failure. That's the root cause of the problem !!

<span>In Visual Studio, the </span><strong>Copy to Output Directory</strong><span> property for your startup batch file or any other dependent files should be set to </span><strong>Copy Always</strong><span> to be sure that your startup batch file is properly deployed to your project on Azure (</span><strong>approot\bin</strong><span> for Web roles, and </span><strong>approot</strong><span> for worker roles). However in our case <strong>Copy to Output Directory</strong> was set to <strong>Do not copy </strong>for 'configuration.xml' file.</span>

<a href="https://msdnshared.blob.core.windows.net/media/2018/08/ConfigurationFile.png"><img src="https://msdnshared.blob.core.windows.net/media/2018/08/ConfigurationFile.png" alt="ConfigurationFile" class="aligncenter wp-image-875 size-full" width="591" height="300" /></a>

&nbsp;

I hope you have got an idea how missing runtime dependencies can lead to Busy state of Azure Cloud Service role.

Happy Learning !]]></content:encoded>
    </item>
    <item>
      <title>Scenario 3 : Autoscale is not triggering for FileUploader role although CPU utilization in one of the instance FileUploader_IN_1 always stays at 100%</title>
      <link>https://docs.microsoft.com/archive/blogs/pratyay/scenario-3-autoscale-is-not-triggering-for-fileuploader-role-although-cpu-utilization-in-one-of-the-instance-fileuploader_in_1-always-stays-at-100</link>
      <pubDate>Sun, 12 Aug 2018 23:30:09 GMT</pubDate>
      <dc:creator><![CDATA[Pratyaydeep Chanda]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/pratyay/?p=785</guid>
      <description><![CDATA[Referring to my blog on Azure Cloud Service Troubleshooting Series, this is the 3rd scenario of the...]]></description>
      <content:encoded><![CDATA[Referring to my blog on <a href="https://blogs.msdn.microsoft.com/pratyay/2018/07/30/cloud-service-troubleshooting-series/">Azure Cloud Service Troubleshooting Series</a>, this is the 3rd scenario of the lab. Please make sure you have followed the lab setup instructions for <em><strong>Compressor</strong> </em>application as per <a href="https://github.com/prchanda/compressor">this</a>, to recreate the problem.

&nbsp;
<h4><span style="text-decoration: underline;color: #008000">Symptom</span></h4>
One of the <strong>FileUploader</strong> role instance (FileUploader_IN_1) is consuming 100% CPU, whereas in the other two instances CPU utilization is normal. As per the lab instruction we have created an autoscale rule for <strong>FileUploader</strong> role based on "Percentage CPU" metric but it is not triggering for some reason. Here are the CPU utilization from all the instances:

&nbsp;

[caption id="attachment_795" align="alignnone" width="750"]<a href="https://msdnshared.blob.core.windows.net/media/2018/08/CpuUtil_Instance_0.png"><img src="https://msdnshared.blob.core.windows.net/media/2018/08/CpuUtil_Instance_0-1024x625.png" alt="CpuUtil_Instance_0" class="wp-image-795" width="750" height="458" /></a> <span style="text-decoration: underline"><strong>CPU utilization for FileUploader_IN_0</strong></span>[/caption]

[caption id="attachment_805" align="alignleft" width="750"]<a href="https://msdnshared.blob.core.windows.net/media/2018/08/CpuUtil_Instance_1.png"><img src="https://msdnshared.blob.core.windows.net/media/2018/08/CpuUtil_Instance_1-1024x626.png" alt="CpuUtil_Instance_1" class="wp-image-805" width="750" height="458" /></a> <span style="text-decoration: underline"><strong>CPU utilization of FileUploader_IN_1</strong></span>[/caption]

[caption id="attachment_815" align="alignleft" width="751"]<a href="https://msdnshared.blob.core.windows.net/media/2018/08/CpuUtil_Instance_2.png"><img src="https://msdnshared.blob.core.windows.net/media/2018/08/CpuUtil_Instance_2-1024x628.png" alt="CpuUtil_Instance_2" class="wp-image-815" width="751" height="460" /></a> <span style="text-decoration: underline"><strong>CPU utilization for FileUploader_IN_2</strong></span>[/caption]

&nbsp;
<h4><span style="text-decoration: underline;color: #008000">Troubleshooting</span></h4>
If you carefully look into the autoscale rule which we have configured, it says the rule will get triggered only if the average CPU utilization of all the role instances is greater than 90, which is not happening in our case.
<div id="jsonOutputWrapper">
<div id="jsonOutputWrapper">
<pre id="jsonOutput" class="nohighlight json"><span class="json-open-bracket">{</span><img class="json-minus" src="https://www.freeformatter.com/3.4.0.1/img/minus.gif" /><span class="json-collapse-1">
<span class="json-indent">   </span><span class="json-property">"properties"</span><span class="json-semi-colon">: </span><span class="json-open-bracket">{</span><img class="json-minus" src="https://www.freeformatter.com/3.4.0.1/img/minus.gif" /><span class="json-collapse-2">
<span class="json-indent">      </span><span class="json-property">"name"</span><span class="json-semi-colon">: </span><span class="json-value">"Autoscale based on CPU metric"</span><span class="json-comma">,</span>
<span class="json-indent">      </span><span class="json-property">"enabled"</span><span class="json-semi-colon">: </span><span class="json-value">true</span><span class="json-comma">,</span>
<span class="json-indent">      </span><span class="json-property">"targetResourceUri"</span><span class="json-semi-colon">: </span><span class="json-value">"/subscriptions/{subscription-id}/resourceGroups/cloudservicelab/providers/Microsoft.ClassicCompute/domainNames/cloudservicelabs/slots/Production/roles/FileUploader"</span><span class="json-comma">,</span>
<span class="json-indent">      </span><span class="json-property">"profiles"</span><span class="json-semi-colon">: </span><span class="json-open-bracket">[</span><img class="json-minus" src="https://www.freeformatter.com/3.4.0.1/img/minus.gif" /><span class="json-collapse-3">
<span class="json-indent">         </span><span class="json-open-bracket">{</span><img class="json-minus" src="https://www.freeformatter.com/3.4.0.1/img/minus.gif" /><span class="json-collapse-4">
<span class="json-indent">            </span><span class="json-property">"name"</span><span class="json-semi-colon">: </span><span class="json-value">"Auto created scale condition"</span><span class="json-comma">,</span>
<span class="json-indent">            </span><span class="json-property">"capacity"</span><span class="json-semi-colon">: </span><span class="json-open-bracket">{</span><img class="json-minus" src="https://www.freeformatter.com/3.4.0.1/img/minus.gif" /><span class="json-collapse-5">
<span class="json-indent">               </span><span class="json-property">"minimum"</span><span class="json-semi-colon">: </span><span class="json-value">"1"</span><span class="json-comma">,</span>
<span class="json-indent">               </span><span class="json-property">"maximum"</span><span class="json-semi-colon">: </span><span class="json-value">"4"</span><span class="json-comma">,</span>
<span class="json-indent">               </span><span class="json-property">"default"</span><span class="json-semi-colon">: </span><span class="json-value">"1"</span>
<span class="json-indent">            </span></span><span class="json-close-bracket">}</span><span class="json-comma">,</span>
<span class="json-indent">            </span><span class="json-property">"rules"</span><span class="json-semi-colon">: </span><span class="json-open-bracket">[</span><img class="json-minus" src="https://www.freeformatter.com/3.4.0.1/img/minus.gif" /><span class="json-collapse-6">
<span class="json-indent">               </span><span class="json-open-bracket">{</span><img class="json-minus" src="https://www.freeformatter.com/3.4.0.1/img/minus.gif" /><span class="json-collapse-7">
<span class="json-indent">                  </span><span class="json-property">"scaleAction"</span><span class="json-semi-colon">: </span><span class="json-open-bracket">{</span><img class="json-minus" src="https://www.freeformatter.com/3.4.0.1/img/minus.gif" /><span class="json-collapse-8">
<span class="json-indent">                     </span><span class="json-property">"direction"</span><span class="json-semi-colon">: </span><span class="json-value">"Increase"</span><span class="json-comma">,</span>
<span class="json-indent">                     </span><span class="json-property">"type"</span><span class="json-semi-colon">: </span><span class="json-value">"ChangeCount"</span><span class="json-comma">,</span>
<span class="json-indent">                     </span><span class="json-property">"value"</span><span class="json-semi-colon">: </span><span class="json-value">"1"</span><span class="json-comma">,</span>
<span class="json-indent">                     </span><span class="json-property">"cooldown"</span><span class="json-semi-colon">: </span><span class="json-value">"PT10M"</span>
<span class="json-indent">                  </span></span><span class="json-close-bracket">}</span><span class="json-comma">,</span>
<span class="json-indent">                  </span><span class="json-property">"metricTrigger"</span><span class="json-semi-colon">: </span><span class="json-open-bracket">{</span><img class="json-minus" src="https://www.freeformatter.com/3.4.0.1/img/minus.gif" /><span class="json-collapse-9">
<span class="json-indent">                     </span><span class="json-property">"metricName"</span><span class="json-semi-colon">: </span><span class="json-value">"Percentage CPU"</span><span class="json-comma">,</span>
<span class="json-indent">                     </span><span class="json-property">"metricNamespace"</span><span class="json-semi-colon">: </span><span class="json-value">""</span><span class="json-comma">,</span>
<span class="json-indent">                     </span><span class="json-property">"metricResourceUri"</span><span class="json-semi-colon">: </span><span class="json-value">"/subscriptions/{subscription-id}/resourceGroups/cloudservicelab/providers/Microsoft.ClassicCompute/domainNames/cloudservicelabs/slots/Production/roles/FileUploader"</span><span class="json-comma">,</span>
<span class="json-indent">                     </span><span style="color: #0000ff"><strong><span class="json-property">"operator"</span><span class="json-semi-colon">: </span><span class="json-value">"GreaterThan"</span></strong></span><span class="json-comma">,</span>
<span class="json-indent">                     </span><span style="color: #0000ff"><strong><span class="json-property">"statistic"</span><span class="json-semi-colon">: </span><span class="json-value">"Average"</span></strong></span><span class="json-comma">,</span>
<span class="json-indent">                     </span><span style="color: #0000ff"><strong><span class="json-property">"threshold"</span><span class="json-semi-colon">: </span><span class="json-value">90</span></strong></span><span class="json-comma">,</span>
<span class="json-indent">                     </span><span class="json-property">"timeAggregation"</span><span class="json-semi-colon">: </span><span class="json-value">"Average"</span><span class="json-comma">,</span>
<span class="json-indent">                     </span><span class="json-property">"timeGrain"</span><span class="json-semi-colon">: </span><span class="json-value">"PT5M"</span><span class="json-comma">,</span>
<span class="json-indent">                     </span><span class="json-property">"timeWindow"</span><span class="json-semi-colon">: </span><span class="json-value">"PT30M"</span>
<span class="json-indent">                  </span></span><span class="json-close-bracket">}</span>
<span class="json-indent">               </span></span><span class="json-close-bracket">}</span>
<span class="json-indent">            </span></span><span class="json-close-bracket">]</span>
<span class="json-indent">         </span></span><span class="json-close-bracket">}</span>
<span class="json-indent">      </span></span><span class="json-close-bracket">]</span><span class="json-comma">,</span>
<span class="json-indent">      </span><span class="json-property">"notifications"</span><span class="json-semi-colon">: </span><span class="json-empty-array">[]</span><span class="json-comma">,</span>
<span class="json-indent">      </span><span class="json-property">"targetResourceLocation"</span><span class="json-semi-colon">: </span><span class="json-value">"southcentralus"</span>
<span class="json-indent">   </span></span><span class="json-close-bracket">}</span>
<span class="json-indent"></span></span><span class="json-close-bracket">}
</span></pre>
</div>
<a href="https://docs.microsoft.com/en-us/azure/vs-azure-tools-diagnostics-for-cloud-services-and-virtual-machines">Set up diagnostics for Azure Cloud Services</a> and check the CPU utilization of each role instance from <strong>WADPerformanceCountersTable</strong>. You can also fetch metric data for the cloud service role using <a href="https://docs.microsoft.com/en-us/rest/api/monitor/metrics/list">this REST API</a> or <a href="https://gallery.technet.microsoft.com/How-to-use-PowerShell-to-bc7aab03">PowerShell</a> as well.

You can also monitor the average CPU utilization of FileUploader role from <strong>Metrics </strong>tab in you cloud service resource. So as you can see from the below graph the average CPU utilization is around 33.35% which is quite below the threshold.

<a href="https://msdnshared.blob.core.windows.net/media/2018/08/CPU-Metric.png"><img src="https://msdnshared.blob.core.windows.net/media/2018/08/CPU-Metric-1024x445.png" alt="CPU-Metric" class="alignleft size-large wp-image-835" width="1024" height="445" /></a>

&nbsp;

So the bottom line is autoscaling rules that use a detection mechanism based on a measured trigger attribute (such as CPU usage) use an aggregated value over time, rather than instantaneous values, to trigger an autoscaling action. By default, the aggregate is an average of the values across all the instances of the role. So, in case of multiple instances, each PaaS VM reports a number for percentage CPU. To consolidate these, the cloud service role calculates the “statistic” across all of the instances. For instance, if there were three instances in a cloud service role, one running at 30% CPU, second one at 60% and another running at 90% CPU, the role would emit an average CPU utilization of 60%.

</div>
I hope you have got an idea how autoscaling works in Azure Cloud Service.

Happy Learning !]]></content:encoded>
    </item>
    <item>
      <title>Scenario 2 : AssemblyBinder role instances is throwing System.IO.IOException -There is not enough space on the disk and stuck between Busy and Restarting state</title>
      <link>https://docs.microsoft.com/archive/blogs/pratyay/scenario-2-assemblybinder-role-instances-is-throwing-system-io-ioexception-there-is-not-enough-space-on-the-disk-and-stuck-in-busy-state</link>
      <pubDate>Sun, 12 Aug 2018 20:21:00 GMT</pubDate>
      <dc:creator><![CDATA[Pratyaydeep Chanda]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/pratyay/?p=735</guid>
      <description><![CDATA[Referring to my blog on Azure Cloud Service Troubleshooting Series, this is the 2nd scenario of the...]]></description>
      <content:encoded><![CDATA[Referring to my blog on <a href="https://blogs.msdn.microsoft.com/pratyay/2018/07/30/cloud-service-troubleshooting-series/">Azure Cloud Service Troubleshooting Series</a>, this is the 2nd scenario of the lab. Please make sure you have followed the lab setup instructions for <em><strong>Compressor</strong> </em>application as per <a href="https://github.com/prchanda/compressor">this</a>, to recreate the problem.

&nbsp;
<h4><span style="text-decoration: underline"><span style="color: #008000;text-decoration: underline">Symptom</span></span></h4>
<strong>AssemblyBinder </strong>role instance of <em>Compressor</em> application is throwing the below unhandled exception in the azure portal blade and stuck between Busy and Restarting state.
<div id="htmlOutputWrapper">
<pre id="htmlOutput" class="html"><code class="hljs xml"><span style="color: #ff0000">Unhandled Exception: There is not enough space on the disk. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.WriteCore(Byte[] buffer, Int32 offset, Int32 count) at Ionic.Zip.ZipEntry.ExtractAndCrc(Stream archiveStream, Stream targetOutput, Int16 compressionMethod, Int64 compressedFileDataSize, Int64 uncompressedSize) at Ionic.Zip.ZipEntry.ExtractToStream(Stream archiveStream, Stream output, EncryptionAlgorithm encryptionAlgorithm, Int32 expectedCrc32) at Ionic.Zip.ZipEntry.InternalExtractToBaseDir(String baseDir, String password, ZipContainer zipContainer, ZipEntrySource zipEntrySource, String fileName) at Ionic.Zip.ZipFile._InternalExtractAll(String path, Boolean overrideExtractExistingProperty) at AssemblyBinder.WorkerRole.OnStart() in D:\compressor\AssemblyBinder\WorkerRole.cs:line 56 at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.InitializeRoleInternal(RoleType roleTypeEnum) at Microsoft.WindowsAzure.ServiceRuntime.Implementation.Loader.RoleRuntimeBridge.
<span class="hljs-tag">&lt;<span class="hljs-name">InitializeRole</span>&gt;</span>
b__0() at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() ' [2018-08-12T14:47:25Z] Last exit time: [2018/08/12, 14:47:25.965].
</span></code></pre>
</div>
&nbsp;
<h4><span style="text-decoration: underline;color: #008000">Troubleshooting</span></h4>
<div id="htmlOutputWrapper">From the error callstack it looks like this WorkerRole is performing some unzip or extract operation at <strong>OnStart()</strong> method but it is failing due to insufficient storage. The next obvious question that will come to your mind is where exactly <strong>WaWorkerHost.exe</strong> process is extracting the file ?</div>
<div></div>
<div>In order to find out the answer, the only tool that comes to my mind which always helps me in troubleshooting these kind of issues is none other than - <a href="https://docs.microsoft.com/en-us/sysinternals/downloads/procmon">Process Monitor</a> !  ..... So let's take a ProcMon trace and see what we can find...</div>
&nbsp;
<div><a href="https://msdnshared.blob.core.windows.net/media/2018/08/DiskFull.png"><img src="https://msdnshared.blob.core.windows.net/media/2018/08/DiskFull-1024x165.png" alt="Disk Full" class="alignleft size-large wp-image-755" width="1024" height="165" /></a></div>
<div>

&nbsp;

And there you go ..... Gotcha !

<strong>WaWorkerHost.exe</strong> process is writing some file in it's default temporary directory which has a maximum size of 100 MB, which may become full at some point. Upon navigating to the <strong>RoleTemp</strong> directory I found that disk space quota is indeed getting exhausted for that directory.

&nbsp;

</div>
<a href="https://msdnshared.blob.core.windows.net/media/2018/08/RoleTempLargeFile.png"><img src="https://msdnshared.blob.core.windows.net/media/2018/08/RoleTempLargeFile-1024x168.png" alt="RoleTemp Large File" class="alignleft size-large wp-image-775" width="1024" height="168" /></a>

We figured out the cause of the problem, but what should I do when I am running out of space in <strong>RoleTemp</strong> location ? <a href="https://docs.microsoft.com/en-us/azure/cloud-services/cloud-services-troubleshoot-default-temp-folder-size-too-small-web-worker-role">Here</a> is the answer :-) ....Hence I have configured a local storage resource, and pointed the TEMP and TMP directories to point to the path of the local storage resource like below:

&nbsp;

The local resource declaration must have been added to the service definition file for AssemblyBinder role.
<div id="xmlOutputWrapper">
<pre id="xmlOutput" class="xml"><span style="color: #0000ff"><code class="hljs"><span class="php"><span class="hljs-meta">&lt;?</span>xml version=<span class="hljs-string">"1.0"</span> encoding=<span class="hljs-string">"UTF-8"</span><span class="hljs-meta">?&gt;</span></span>
<span class="hljs-tag">&lt;<span class="hljs-name">LocalResources</span>&gt;</span>
   <span class="hljs-tag">&lt;<span class="hljs-name">LocalStorage</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"FileStorage"</span> <span class="hljs-attr">cleanOnRoleRecycle</span>=<span class="hljs-string">"true"</span> <span class="hljs-attr">sizeInMB</span>=<span class="hljs-string">"200"</span> /&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">LocalResources</span>&gt;</span>
</code></span></pre>
</div>
This modification should be performed within the <a href="https://msdn.microsoft.com/library/microsoft.windowsazure.serviceruntime.roleentrypoint.onstart.aspx">RoleEntryPoint.OnStart</a> method.
<div id="htmlOutputWrapper">
<pre id="htmlOutput" class="html"><code class="hljs xml">localResource = RoleEnvironment.GetLocalResource("FileStorage");
Environment.SetEnvironmentVariable("TMP", localResource.RootPath);
Environment.SetEnvironmentVariable("TEMP", localResource.RootPath);
</code></pre>
</div>
&nbsp;

I hope you have got an idea how to troubleshoot default TEMP folder size issues in Azure Cloud Service.

Happy Learning !]]></content:encoded>
    </item>
    <item>
      <title>Scenario 1 : ZipEngine role is looping between Restarting and Busy state throwing an unhandled exception: Could not load file or assembly - An attempt was made to load a program with an incorrect format</title>
      <link>https://docs.microsoft.com/archive/blogs/pratyay/scenario-1-zipengine-role-is-looping-between-restarting-and-busy-state-throwing-an-unhandled-exception-could-not-load-file-or-assembly-an-attempt-was-made-to-load-a-program-with-an-incorrect-form</link>
      <pubDate>Sun, 12 Aug 2018 17:04:11 GMT</pubDate>
      <dc:creator><![CDATA[Pratyaydeep Chanda]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/pratyay/?p=705</guid>
      <description><![CDATA[Referring to my blog on Azure Cloud Service Troubleshooting Series, this is the 1st scenario of the...]]></description>
      <content:encoded><![CDATA[Referring to my blog on <a href="https://blogs.msdn.microsoft.com/pratyay/2018/07/30/cloud-service-troubleshooting-series/">Azure Cloud Service Troubleshooting Series</a>, this is the 1st scenario of the lab. Please make sure you have followed the lab setup instructions for <em><strong>Compressor</strong> </em>application as per <a href="https://github.com/prchanda/compressor">this</a>, to recreate the problem.

&nbsp;
<h4><span style="text-decoration: underline"><span style="color: #008000;text-decoration: underline">Symptom</span></span></h4>
<strong>ZipEngine</strong> role instance of <em>Compressor</em> application is constantly looping between Restarting and Busy state throwing the below unhandled exception in the azure portal blade:
<div id="htmlOutputWrapper">
<pre id="htmlOutput" class="html"><code class="hljs xml"><span style="color: #ff0000">Unhandled Exception: Could not load file or assembly 'WorkerAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format. at ZipEngine.WorkerRole.OnStart() at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.InitializeRoleInternal(RoleType roleTypeEnum) at Microsoft.WindowsAzure.ServiceRuntime.Implementation.Loader.RoleRuntimeBridge.
<span class="hljs-tag">&lt;<span class="hljs-name">InitializeRole</span>&gt;</span>
b__0() at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() ' [2018-08-12T11:28:39Z] Last exit time: [2018/08/12, 11:28:39.434].
</span></code></pre>
&nbsp;

</div>
<h4><span style="text-decoration: underline"><span style="color: #008000;text-decoration: underline">Troubleshooting</span></span></h4>
If your role does not start, or is recycling between the initializing, busy, and stopping states, your code may be throwing an unhandled exception within one of the lifecycle events each time the role restarts. So if you look into the above callstack carefully you would notice that an unhandled exception is being through from <span><strong>OnStart()</strong></span> method of your worker role. The best place to begin troubleshooting for these kind of scenarios is to check <strong>Windows Azure Event Logs </strong>which c<span>ontains key diagnostic output from the Windows Azure Runtime, including information such as Role starts/stops, startup tasks, OnStart start and stop, OnRun start, crashes, recycles, etc.
</span>
<div id="htmlOutputWrapper">
<pre id="htmlOutput" class="html"><span style="color: #ff0000"><code class="hljs xml"><span style="color: #ff0000"><strong>System.BadImageFormatException</strong>
Process ID: 5132
Process Name: WaWorkerHost
Thread ID: 4
AppDomain Unhandled Exception for role ZipEngine_IN_0
Exception: Could not load file or assembly 'WorkerAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.
at ZipEngine.WorkerRole.OnStart()
at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.InitializeRoleInternal(RoleType roleTypeEnum)
at Microsoft.WindowsAzure.ServiceRuntime.Implementation.Loader.RoleRuntimeBridge.
<span class="hljs-tag">&lt;<span class="hljs-name">InitializeRole</span>&gt;</span>
b__0()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
</span></code></span></pre>
</div>
&nbsp;

So...now we got a bit more detail about the exception from <strong>Windows Azure Event Logs</strong> which says that process hosting worker role is not able to load the assembly 'WorkerAssembly' due to <span style="color: #ff0000"><strong>System.BadImageFormatException</strong><span style="color: #000000">. In g</span></span>eneral when a process is not able to load an assembly, it's always a good practice to capture Fusion logs. Make the following registry key changes under the path <strong>[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion]</strong> to enable fusion logging. Give <strong>Everyone - Full Control</strong> permission to the fusion log path folder (C:\FusionLogs).

&nbsp;

<span><a href="https://msdnshared.blob.core.windows.net/media/2018/08/FusionLog.png"><img src="https://msdnshared.blob.core.windows.net/media/2018/08/FusionLog-1024x234.png" alt="Fusion Log Registry" class="alignleft size-large wp-image-725" width="1024" height="234" /></a></span>

&nbsp;

Upon checking the fusion log for 'WorkerAssembly' I got some interesting facts to further dig into.
<div id="htmlOutputWrapper">
<pre id="htmlOutput" class="html"><code class="hljs xml">*** Assembly Binder Log Entry  (8/12/2018 @ 12:51:00 PM) ***
The operation failed.
<span style="color: #ff0000"><strong>Bind result: hr = 0x8007000b. An attempt was made to load a program with an incorrect format.</strong></span>
Assembly manager loaded from:  D:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable  E:\base\x64\WaWorkerHost.exe
--- A detailed error log follows. 
=== Pre-bind state information ===
LOG: DisplayName = WorkerAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///E:/approot
LOG: Initial PrivatePath = E:\approot
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = RoleManager
Calling assembly : ZipEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: E:\approot\ZipEngine.dll.config
LOG: Using host configuration file: 
LOG: Using machine configuration file from D:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///E:/approot/WorkerAssembly.DLL.
LOG: Assembly download was successful. Attempting setup of file: E:\approot\WorkerAssembly.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: WorkerAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
<span style="color: #ff0000"><strong>ERR: Invalid assembly platform or ContentType in file (hr = 0x8007000b).</strong></span>
ERR: Run-from-source setup phase failed with hr = 0x8007000b.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.
</code></pre>
</div>
&nbsp;

The above highlighted error message in fusion logs states that something is wrong in the bitness of the assembly ! If we look into the MSDN documentation of <span><a href="https://msdn.microsoft.com/en-us/library/system.badimageformatexception(v=vs.110).aspx">BadImageFormatException</a>, then the most probable cause of this error correlates to this - </span>

"<em><span style="color: #800000">A DLL or executable is loaded as a 64-bit assembly, but it contains 32-bit features or resources. For example, it relies on COM interop or calls methods in a 32-bit dynamic link library. To address this exception, set the project's <strong>Platform target</strong> property to x86 (instead of x64 or AnyCPU) and recompile.</span></em>"

In order to find out the bitness of the assembly you can run any .NET decompiler of your choice. I prefer <a href="https://github.com/icsharpcode/ILSpy">ILSpy</a> and this is what I found after decompiling 'WorkerAssembly' .... Bingo  ! This is 32-bit assembly (x86).
<div id="htmlOutputWrapper">
<pre id="htmlOutput" class="html"><code class="hljs xml">// C:\WorkerAssembly.dll
<span style="color: #0000ff"><strong>// WorkerAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</strong></span>
// Global type: <span class="hljs-tag" style="color: #000080">
&lt;<span class="hljs-name">Module</span>&gt;
</span><span style="color: #0000ff"><strong>// Architecture: x86</strong></span>
// Runtime: .NET 4.0
</code></pre>
</div>
Azure is a 64-bit environment. Therefore, .NET assemblies compiled for a 32-bit target won't work on Azure. <span>To address this exception, set 'WorkerAssembly' project's </span><strong>Platform target</strong><span> property to x64 (instead of x86 or AnyCPU) and recompile.</span>

If you review the code of WorkerRole.cs for ZipEngine role you would notice below two lines of code which was actually loading the assembly 'WorkerAssembly' and performing some function. Since it was a 32-bit assembly the <strong>WaWorkerHost.exe </strong>was not able to load that assembly.

<span style="color: #3366ff"> WorkerAssembly.WorkerAssembly workerAssembly = new WorkerAssembly.WorkerAssembly();</span>
<span style="color: #3366ff">workerAssembly.DoWork();</span>

&nbsp;

I hope you have got an idea how to troubleshoot issues related to assembly that targets wrong platform in Azure Cloud Service.

Happy Learning !]]></content:encoded>
    </item>
    <item>
      <title>Azure Cloud Service Troubleshooting Series</title>
      <link>https://docs.microsoft.com/archive/blogs/pratyay/cloud-service-troubleshooting-series</link>
      <pubDate>Mon, 30 Jul 2018 11:21:54 GMT</pubDate>
      <dc:creator><![CDATA[Pratyaydeep Chanda]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/pratyay/?p=685</guid>
      <description><![CDATA[I am excited to write my second troubleshooting blog series on Azure Cloud Service after API...]]></description>
      <content:encoded><![CDATA[I am excited to write my second troubleshooting blog series on Azure Cloud Service after API Management. If you are interested to get your hands dirty on APIM, check out <a href="https://blogs.msdn.microsoft.com/pratyay/2018/07/29/azure-api-management-troubleshooting-series/">this</a> blog series now !!

Cloud service is one of most popular Azure PaaS service among web developers. So I thought of simulating some labs on various issues faced by the customers commonly. <a href="https://blogs.msdn.com/b/kwill/archive/2013/08/09/windows-azure-paas-compute-diagnostics-data.aspx" rel="nofollow">Kevin Williamson's blog series</a> includes some of the common problems faced by the customers while dealing with cloud service and how to troubleshoot those issues using various tools and logs. In this blog I am going to focus on some more common scenarios that we may face while developing and deploying cloud service solution to Azure.

In order to simulate the issues I have developed 3 cloud service applications and below are the links for instructions that you need to follow to setup the labs for each application:
<ul>
 	<li><a href="https://github.com/prchanda/compressor">Compressor</a></li>
 	<li><a href="https://github.com/prchanda/superconvertor">Super Convertor</a></li>
 	<li><a href="https://github.com/prchanda/visitortracker">Visitor Tracker</a></li>
</ul>
Let's deep dive into the troubleshooting series on Azure Cloud Service:
<ul>
 	<li style="list-style-type: none">
<ul>
 	<li><span style="color: #0000ff"><a href="https://blogs.msdn.microsoft.com/pratyay/2018/08/12/scenario-1-zipengine-role-is-looping-between-restarting-and-busy-state-throwing-an-unhandled-exception-could-not-load-file-or-assembly-an-attempt-was-made-to-load-a-program-with-an-incorrect-form/">Scenario 1 : An instance of <strong>ZipEngine </strong>role is looping between Restarting and Busy state throwing an unhandled exception:</a></span> <span style="color: #ff0000"><span style="color: #ff0000"><span style="color: #ff0000"><span style="color: #ff0000"><a href="https://blogs.msdn.microsoft.com/pratyay/2018/08/12/scenario-1-zipengine-role-is-looping-between-restarting-and-busy-state-throwing-an-unhandled-exception-could-not-load-file-or-assembly-an-attempt-was-made-to-load-a-program-with-an-incorrect-form/"><strong><span style="color: #ff0000"><em>Could not load file or assembly -</em> An attempt was made to load a program with an incorrect format</span></strong></a><span style="color: #000000">.</span></span></span></span></span></li>
 	<li><a href="https://blogs.msdn.microsoft.com/pratyay/2018/08/12/scenario-2-assemblybinder-role-instances-is-throwing-system-io-ioexception-there-is-not-enough-space-on-the-disk-and-stuck-in-busy-state/">Scenario 2 : <strong>AssemblyBinder</strong> role instances is throwing <em><strong><span style="color: #ff0000">System.IO.IOException -There is not enough space on the disk</span></strong></em></a><span style="color: #000000"><span style="color: #000000"><span style="color: #000000"><span style="color: #000000"><a href="https://blogs.msdn.microsoft.com/pratyay/2018/08/12/scenario-2-assemblybinder-role-instances-is-throwing-system-io-ioexception-there-is-not-enough-space-on-the-disk-and-stuck-in-busy-state/"> and stuck between Busy and Restarting state</a>.</span></span></span></span></li>
 	<li><a href="https://blogs.msdn.microsoft.com/pratyay/2018/08/12/scenario-3-autoscale-is-not-triggering-for-fileuploader-role-although-cpu-utilization-in-one-of-the-instance-fileuploader_in_1-always-stays-at-100/">Scenario 3 : Autoscale is not triggering for <strong>FileUploader </strong>role although CPU utilization in one of the instance FileUploader_IN_1 always stays at 100%</a>.</li>
 	<li><a href="https://blogs.msdn.microsoft.com/pratyay/2018/08/13/scenario-4-processorengine-role-is-stuck-in-busy-state-stating-preparing-to-start-role-system-is-initializing/">Scenario 4 : <strong>ProcessorEngine </strong>role is stuck in Busy state stating - <em><strong>Preparing to start role... System is initializing</strong></em></a>.</li>
 	<li><a href="https://blogs.msdn.microsoft.com/pratyay/2018/08/13/scenario-5-my-website-is-throwing-http-error-503-the-service-is-unavailable-when-browsed-over-the-default-cloud-service-domain-url-cloudapp-net/">Scenario 5 : My website is throwing <em><span style="color: #ff0000"><strong>HTTP Error 503. The service is unavailable </strong></span></em></a><span style="color: #ff0000"><span style="color: #000000"><a href="https://blogs.msdn.microsoft.com/pratyay/2018/08/13/scenario-5-my-website-is-throwing-http-error-503-the-service-is-unavailable-when-browsed-over-the-default-cloud-service-domain-url-cloudapp-net/">when browsed over the default cloud service domain url (*.cloudapp.net)</a>.</span></span></li>
 	<li><a href="https://blogs.msdn.microsoft.com/pratyay/2018/08/14/scenario-6-not-able-to-rdp-to-only-healthmonitor-worker-role-and-getting-an-error-this-computer-cant-connect-to-the-remote-computer/">Scenario 6 : Not able to RDP to <em>only</em> 'HealthMonitor' worker role instance and getting an error : <span style="color: #ff0000"><strong><em>This computer can't connect to the remote computer</em></strong><em></em></span></a><em>.</em><span style="color: #ff0000"><strong>
</strong></span></li>
 	<li><a href="https://blogs.msdn.microsoft.com/pratyay/2018/08/15/scenario-7-i-cannot-access-my-website-although-all-role-instances-are-in-running-state/">Scenario 7 : I cannot access my website, although all role instances are in running state</a>.</li>
 	<li><a href="https://blogs.msdn.microsoft.com/pratyay/2018/08/15/scenario-8-asp-net-signalr-application-is-not-working-in-azure-cloud-service/">Scenario 8 : ASP.NET SignalR application is not working in azure cloud service</a>.</li>
</ul>
</li>
</ul>
Hope you have enjoyed and learnt a bit of Cloud Service troubleshooting through this series. I will keep on adding more scenarios to this list, so have a close watch on this blog 🙂

Happy learning !]]></content:encoded>
    </item>
  </channel>
</rss>