I have a .NET 4 Windows Service written in C# running on Windows Server 2008, which when monitored with PerfMon, appears to consume 2,500 handles per hour. The "Handle Count" counter climbs ever upwards.
When I look at the handles using ProcExp with the "Show Unnamed Handles and Mappings" option selected, there are thousands of Event and Semaphore handles listed. Most seem unnamed. I looked in the source code, and there are no explicit uses of AutoResetEvent or ManualResetEvent.
The Private Bytes counter climbs and falls. I haven't watched the process for more than a couple of hours but will leave it being monitored overnight.
The service runs on a remote server, so I can't directly attach a debugger, and will probably have to dump the process and analyse it with WinDBG or similar.
Is it possible to locate one of the handles and find out what it points to and/or what might "own" it? If so how?
In response to comments, here's a summary of what the service does.
The fundamental concept behind troubleshooting is isolation. Isolation in terms of processes and state.
The first thing you need to do is to reproduce the problem in an environment that you control. Try setting this up on your dev machine, if there are services that would take too long to set up in a dev environment consider mocking them out.
Once you are in control of the environment you can start paring back the code being executed by mocking it or stubbing it out.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With