MSDN > 論壇首頁 > Building Development and Diagnostic Tools for .Net > Windows Service Crashes and JIT debug
發問發問
 

問題Windows Service Crashes and JIT debug

  • Thursday, 4 June, 2009 23:52webcliff2 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     

    All,

    Sorry, this is not a short post, english is not my native language, if I confuse you, please ask, I will try to explain.

    My Windows Service  (myservice.exe) is based on .NET 2.0 framework (x86 32bit XP SP2), it uses threading and remoting, sometimes crashes.
    When it crashes, I could found a log event from event viewer, sometimes I could not.

    ==============
    Event Type: Error
    Event Source: .NET Runtime 2.0 Error Reporting
    Event Category: None
    Event ID: 5000
    Date:  5/30/2009
    Time:  7:46:40 AM
    User:  N/A
    Computer: OEM-IDKVIEBJAWI
    Description:
    EventType clr20r3, P1 myservice.exe, P2 1.0.5.74, P3 4a121d7c, P4 mscorlib, P5 2.0.0.0, P6 471ebc5b, P7 1937, P8 0, P9 system.indexoutofrangeexception, P10 NIL.
    ==============

    I have been trying to setup the registry to capture a memory dump, for example, I use these seetings:

    (I use windbg version 6.11.0001 x86 32bit)

    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework]
    "DbgManagedDebugger"="\"C:\\Program Files\\Debugging Tools for Windows\\cdb.exe\" -pv -p %ld -c \".dump /u /ma c:\\crashdump.dmp;.kill;qd\""
    "DbgJITDebugLaunchSetting"=dword:00000002

    It works with my test managed console application and winform application, their crash all create dump files.

    BUT, no matter how I try, I just could not get these settings to work with windows service (myservice.exe)


    Here are my questions:

    1.Who add the log entry to windows event viewer, why sometimes it is there and sometimes it is not when myservice.exe crashes?

    2.How do I capture the randomly crashing myservice.exe's memory dump?

    3.Why the current registry setting does not work?

    • 已編輯webcliff2 Friday, 5 June, 2009 18:21meanful title
    • 已編輯webcliff2 Thursday, 4 June, 2009 23:53os version
    •  

所有回覆

  • Friday, 5 June, 2009 14:02p.b.a 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    When your service starts register for the AppDomain UnhandledException event and do you own logging - this way you have control over what's logged. Without knowing what the how the service works if you don't see any entry in the event log maybe it did not crash, it just terminated for whatever reason.

    Have you tried using AeDebug registry key instead of DbgManagedDebugger ? (http://technet.microsoft.com/en-us/library/cc738371(WS.10).aspx).
  • Friday, 5 June, 2009 17:39webcliff2 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     

    p.b.a.

    Thanks for help!

    I did run drwtsn32 -i (Dr Watson, it sets AeDebug registry key ) and configure Dr Watson to capture all un-managed process crashes.
    It did not help with myservice.exe crash, I am assuming it is because myservice.exe is a managed windows service.

    Unfortunately I do not have access to source code , can't take AppDomain.UnhandledException approach.

    • 已編輯webcliff2 Friday, 5 June, 2009 17:41missing words
    •  
  • Monday, 8 June, 2009 19:52Jon LangdonMSFT, 擁有者使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     

    A few questions:

    What version of the the CLR are you using (version of c:\windows\microsoft.net\framework\v2.0.50727\mscorwks.dll will be sufficient)?
    What account is the service running as?
    Is the service interactive? I.e. does it have UI (even if it's just a console window)?

    Something to try in order to narrow down the point of failure:
    Can you remove the commands from your DbgManagedDebugger registration? I.e. just set it to "C:\program files\debugging tools for windows\cdb.exe" -pv -p %ld and see if the debugger is launched. If your service is non-interactive you won't see any debugger UI, so just check task manager and see if cdb.exe is running.

    If that works we'll see if we can figure out why the command(s) are failing.

    If that doesn't work can you provide a simple repro? Simplify the service code as much as possible and let us know how you're installing it.

    Regards,
    Jon

  • Tuesday, 9 June, 2009 19:13webcliff2 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Jon,

    Thanks for help!

    I have different versions of CLR (2.0 and 3.0) installed, myservice.exe was built with 2.0, and looks like it is loading C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll ( reported by Process Explorer)
    It uses "Local System" account and the service is not interactive <- I think, how do I check?

    Setting DbgManagedDebugger to "C:\program files\debugging tools for windows\cdb.exe" -pv -p %ld didn't fix the issue, I can not find any cdb.exe process running.

    I am trying to see if I can create a simple repro.


    The strange thing is, I think I managed to get it to work at some point by checking "Allow service to interact with desktop" on myservice.exe's service property.  BUT today, checking the same checkbox does not work any more --> really confused by this one.

    Regards.

     
  • Wednesday, 10 June, 2009 19:06webcliff2 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Okay, I think I figured out the strange error regarding to "Allow service to interact with desktop" option.
    It has a lot to do with multi-threading.

    Basically, thread 1 and thread 2 use the same code, they will be probably generating the same exception:
    thread 1 throws an exception which was caught by DbgManagedDebugger, DbgManagedDebugger starts to take over.... but almost at the same time, thread 2 throws a new exception - no sure how the new exception is going to affect the on-going taking-over process of DbgManagedDebugger, I think it ends both myservice process and cdb process - this explains why sometimes it works but sometimes it does not work.

    My problem has been sloved. thanks for help!

    There are still a few questions left though:
    1. Who add the log entry to windows event viewer, why sometimes it is there and sometimes it is not when myservice.exe crashes?
    2. "Allow service to interact with desktop" option fixed my problem, but I know very little about the reason why, is there any further reading about the difference between interactive app and non-interactive app? 
    • 已編輯webcliff2 Wednesday, 10 June, 2009 19:07typo
    •