If broken it is, fix it you should

Using the powers of the debugger to solve the problems of the world - and a bag of chips    by Tess Ferrandez, ASP.NET Escalation Engineer (Microsoft)

.NET Debugging Demos Lab 1: Hang

.NET Debugging Demos Lab 1: Hang

Rate This
  • Comments 51


This is the first in a series of about 10 labs on .NET debugging.  The lab will use a site called BuggyBits, and as the name suggests the bits are extremely buggy.

To get started, follow the setup instructions posted here.

I have a feeling that these hands-on-labs may generate a lot of questions and although I will try to answer any questions posted in the comments I can’t promise to answer them all so please feel free to answer other readers comments if you know the answer, and make sure that you have followed all the installation instructions.

Note: The questions in the labs (Q: … ) are only meant as an aid when troubleshooting the problem.  I will moderate any comments containing answers to these questions until I have released the lab review (about a week after the orignal lab post in order to give everyone a shot at the labs without answers)

Feel free to comment on the lab format good or bad so that I know what works well and what doesn't for future labs.

Without further a due, here comes Lab 1:

Reproduce the problem:

1. Browse to http://localhost/BuggyBits/FeaturedProducts.aspx
This should take about 5 seconds to show, you can see the start time and execution time the bottom of the page.

2. Open up 5 browsers, all browsing to this site and refresh them simultaneously

Note the execution time for each of them and make sure that the start time is pretty much the same on all (otherwise you probably didn’t run the reg file)

Q:  What are the execution times?

Q:  What is the CPU usage of the w3wp.exe process when reproing the problem? High or low CPU?

Q:  What are some potential reasons for a hang with these symptoms?

Get a memory dump:

1. Start a command window and browse to your debuggers directory.  Type the following command to prepare taking the dump but don’t hit enter quiet yet.
adplus –hang –pn w3wp.exe –quiet

2. Reproduce the problem either by browsing with 5 browsers as you did before or by stressing the site with tinyget with the following command line

tinyget -srv:localhost -uri:/BuggyBits/FeaturedProducts.aspx -threads:30 -loop:50

3. Hit enter in the adplus command window to take the memory dump while the requests are still executing.

Q: In adplus hang mode, what triggers the generation of the memory dump?

Q: What permissions do you need to take a memory dump of a process?

Q: Where are the dumps created? Hint: check the windbg help for adplus/hang mode

Open the dump in Windbg.exe

1. Open windbg and open the memory dump (.dmp file) with File/Open Crash dump.

2. Set up the symbol path (see Information and Setup Instructions for more info)

3. Load sos (see Information and Setup Instructions for more info)

Examine the stacks

1. Examine the native callstacks

~* kb 2000

2. Examine the .net callstacks

~* e !clrstack

Q:  Do you see any patterns or recognize any of the callstacks that suggests a thread is waiting for a synchronization mechanism?

Troubleshoot the hang

1. Determine the ID of the thread owning the lock

Q: What thread owns the lock?

Q: How many threads are waiting for the lock?
Hint: MonitorHeld = 1 for each owner and 2 for each waiter.

2. Pick one of the waiters (Hint: waiters will sit in AwareLock::Enter) and take a look at what it is doing.

~5s                          (move to thread 5, replace 5 with actual thread ID)
kb 2000                    (examine native stack)
!clrstack                    (examine .net stack)

Q: In which .net function is it waiting for the lock?

3. Determine what the owning thread is doing 

~5s                          (move to thread 5, replace 5 with actual thread ID)
kb 2000                    (examine native stack)
!clrstack                    (examine .net stack)

Q: Why is it blocking?

4. Examine the code for .NET method owning the lock to verify your theory.


The following articles may be useful when troubleshooting this hang:

Things to ignore when debugging an ASP.NET Hang - Update for .NET 2.0

A Hang Scenario, Locks and Critical Sections

.NET Hang Debugging Walkthrough

Automated .NET Hang Analysis

Have fun debugging 

  • James,

    It adds all the pages your process touches to the dump, that is why you see a jump in taskmanager (workingset) as it loads them in to the process.  It doesnt really add any more virtual bytes or private bytes...

  • I’ve been wanting to dig into the Test features in Visual Studio Team System for a while to “debug” issues

  • Este fin de semana, como ya sabréis casi todos, se ha celebrado la primera 'iteración' del DevCamp;

  • Earlier this week I got an email from a reader who had a hang in an application and sent in some Debug

  • I am having a problem examining the ,net call stack.   when I run the ~* e !clrstack command I get the message "No export clrstack found"

  • No matter what I run to get an XP virtual machine to serve up more than 2 requests, I cannot get IIS to handle these requests concurrently. I confirmed in regedit that MaxConnections* are both set to 10; I even tried "adsutil set w3svc/MaxConnections 40" that was mentioned elsewhere (http://www.codinghorror.com/blog/archives/000329.html). I have restarted IIS and the virtual machine itself, but multiple requests to FeaturedProducts.aspx always get queued one after another (with start time incrementing by the delay for each one). Is there something I am missing in this setup process to get XP less crippled for development work?

  • It should work just fine on XP. Not sure if w3svc/MaxConnections would really have an effect on this though...  The regfile sets up a global setting on your machine that allows you to make more than the normal 2 outgoing connections.

  • Same results as Adam. I'm not sure how to refresh mulitple IE instances simultaneously, so I used Refresh All with 5 tabs on a single IE browser. Start times were approx 5 seconds apart and execution times were all approx 5 seconds - the opposite of expected. XP SP2; .NET 2.0; Confirmed registry entries and both correctly set to 10. I proceeded with the lab using a dump generated while tinyget was running and saw expected blocking results.

    Also had to load sos differently, perhaps since I'm not using 3.5 on this machine.

  • Scott,

    I am not sure why you are seeing the results you are seeing, they seem to indicate that the reg. settigs are still not correct,  3.5 or not should not make a difference...

  • I kkep getting an error when tryuing to run tinyget against the website. I can browse to it fine. If I use the -t switch it  says: "You do not have permission to view this directory or pageusing the credentials taht you supplied becuase your web browser is sending a WWW-Authenticate header fileds taht the webserver is not configured to accept" Thats using Integrated security. If I set it to anonymous I just get "You are not authorized to view this page".

    So Im not abel to run tinyget to stress test.

    Unfortunately after alot searching I could not find anything related to this message when using Tinyget . Hoping that i may find the anser here

  • @Jason:

    I also got the message 'No export clrstack found' after running ~* e !clrstack

    However, after reading the steps again, it occurred to me that I forgot to load SOS. After doing this the results were as expected.

  • Great works.

    I will read all of your labs.

  • For some reason when I run the app in the browser the w3wp.exe process doesn't show up. If I run in TinyGet it says "cannot send data, because connection is closed" and "Socket Error on Receive", but I believe that just may be a firewall thing. I wonder if I'm just missing something. Thanks for the labs!

  • Likewise, I cannot get my browser instances to load concurrently.  Is there a missing step, such as logoff/logon?  Also, I am using IE8 and Win7 RTM - does that change anything?  Thanks.

  • I had the issue with the browser instances not loading concurrently as well and i believe that is because of changes in IE8 and how browsers share the same space.

    Tinyget should still work and does for me on Win7, and if you want to see two concurrent requests in the browser you can start one browser normally and then one in private mode.

Page 3 of 4 (51 items) 1234
Leave a Comment
  • Please add 3 and 7 and type the answer here:
  • Post