October 22, 2008

Debugging Windows Handles (COM+ crash)

This post explains how to debug COM+ crashing issues using windows debugging tools.

Problem:

The main problem is that the COM+ applications are crashing and reporting event log entries that access violations have occurred. The access violations that are occurring within your “MyCOM” COM+ application is crashing the entire COM+ application and will get restarted on the next activation request.

What I would like to do is to enable PageHeap for this “MyCOM” COM+ application and then configure DebugDiag again to monitor for additional Access Violation exceptions for this process. Here are the precise steps to troubleshoot further.

Action

I’m not sure how many COM+ applications you have running on the machine. When we enable pageheap we have to do it based on process name so ALL dllhost.exe processes would have pageheap enabled. If you only have one or two COM+ applications then it won’t be much of a problem. If you have multiple COM+ applications then you’ll see a memory performance impact on the machine as more memory will be required by each instance of dllhost.exe running on the machine. I’ll assume that you have a lot of COM+ apps so to workaround this we can isolate the “MyCOM” to its own custom COM+ application process using the steps below.

1. Download the Windows Debugging Tools onto the APP server. You can download these tools onto a workstation and just copy the installation directory over to the APP machine if you prefer. We recommend during installation select the directory C:\Debuggers for the location to install these tools. http://www.microsoft.com/whdc/devtools/debugging/installx86.mspx#a  (Current release 6.11.1.404 will be fine)

2. On the APP server navigate to C:\Windows\System32 directory. Find the executable ‘dllhost.exe’. Right click on the file -> select Copy -> then in file explorer go to Edit -> Paste copy. Then rename the copy to ‘mydllhost.exe’. This step effectively just creates a copy of the surrogate process, dllhost.exe, but we isolate and rename this copy to ‘mydllhost.exe’

3. Next let’s enable pageheap for the mydllhost.exe process. Open a command prompt and change directories to where you installed or copied the debugging tools (c:\debuggers). At the command prompt enable pageheap for the mydllhost.exe process by entering the following command:

gflags.exe /p /enable mydllhost.exe

4. Next we need to configure the “MyCOM” COM+ application to launch in ‘mydllhost.exe’ instead of the normal ‘dllhost.exe’ process.

a. Open up Component Services

b. Expand Computers -> My Computer -> COM+ Applications -> Right-click on the “MyCOM” COM+ application and select properties

c. When properties window opens click the “Advanced” tab

d. In the Debugging section on this tab click the checkbox for “Launch in debugger”. This enables the debugger path text box, in this text box remove the current string and replace it with the following string exactly. NOTE: I have already entered the correct process id GUID for your specific COM+ application which I was able to dig out of the crash dumps.

C:\WINDOWS\system32\mydllhost.exe /Processid:{A89A82B5-FE7C-4210-A79F-EBCE8811463C}

e. Then click the OK button to apply these settings change

5. At this point you just need to restart the “MyCOM” COM+ application. You can do this manually within component services, just right click on the COM+ app, select shutdown, then right-click again and select start

6. Open up Task Manager and confirm that you now have a new process called mydllhost.exe running. Since we enabled pageheap for this process name before restarting the COM+ app, pageheap is currently enabled for the mydllhost.exe that’s running

7. Now we just need to configure DebugDiag to monitor the mydllhost.exe process instances and create full user dumps when an access violation occurs

a. Open up DebugDiag 1.1

b. On the Rules tab click the “Add Rule…” button

c. Select Crash rule radio button and click Next

d. Select “A specific process” radio button and click Next

e. Find and select the mydllhost.exe process that’s in the process list. Make sure that the “This process instance only” check box is NOT selected, we need that cleared so that it re-attaches if the COM+ app recycles. Then click Next

f. Click the “Exceptions” button -> Click the “Add Exception…” button -> Click the C0000005 Access Violation exception in the list on the left -> On the right hand side here change the Action Type drop down to Full Userdump and change the action limit number value to 10. -> Click Ok -> Click Save and Close -> Click Next

g. Note the location where the userdumps will be written and then click Next

h. Select “Activate the rule now” radio button and click Finish

8. At this point, we’ve isolated your COM+ application to mydllhost.exe process, and we’ve enabled pageheap for that process. We also have DebugDiag attached and it will create full userdumps when any code violates any memory management problems which appears to be causing the memory corruption we see in the dumps already collected.

Lastly analyze the dump file to see actual problem.

Article:

Pushing the Limits of Windows: Handles

Video:

Understanding handle leaks and how to use !htrace to find them