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
!syncblk

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.

Hints

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 
/Tess

  • PingBack from http://blogs.msdn.com/tess/pages/net-debugging-demos-information-and-setup-instructions.aspx

  • Fantastic, now I've got to eagerly await part 2

  • My colleague Tess Ferrandez just posted this excellent lab that provides you with a sample application

  • Tess Ferrandez har skapat en serie med labbar där hon presenterar vanliga post mortem debugging scenarios.

  • Great post!

    I'm trying to apply the knowledge shared here to some .NET dumps i have lying around to see if i can get to the bottom of the problem and i'm having quite some success in drilling down the debug info. Waiting impatiently for lab part 2 - the crash :)

  • 【原文地址】 Feb 6th Links: ASP.NET, ASP.NET AJAX, Visual Studio, .NET, WPF 【原文发表日期】 Wednesday, February 06

  • Very nice!

  • 【原文地址】 Feb 6th Links: ASP.NET, ASP.NET AJAX, Visual Studio, .NET, WPF 【原文发表日期】 Wednesday, February 06

  • Collegamenti del 6 Febbraio, ASP.NET, ASP.NET AJAX, Visual Studio, .NET, WPF

  • ASP.NETMVC框架路线图更新

    【原文地址】ASP.NETMVCFrameworkRoad-MapUpdate

    【原文发表日期】Tuesday,February12,200...

  • TGIF, almost time for the weekend... but before you leave, here is lab 3. Todays debugging puzzle will

  • Lab 1: HangLab 2: CrashLab 3: MemoryLab 4: High CPU Hang

  • I was just informed by MS tech support that my inability to debug many pages in ASP.NET VS2008 is a known bug which will be fixed in SP1 release date unknown at this time.

    This is with a converted application. I have done a new application with no problems.

    Can this be right? It doesn't make sense that there wouldn't be a lot of loud noise out there if everyone was having this problem.

  • I'm not exactly sure what issues you have debugging in VS 2008 so it is a bit hard to say.  

  • When you place a breakpoint in code and run to it it crashes VS2008 upon reaching that breakpoint, or upon stepping one or 2 lines beyond the break line. IOWs debugging can't happen in some pages of converted projects.

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