Detect WCF channel leaking using Windbg

839 views Asked by At

I have WCF service with per session service mode and using WIF for authentication/authorization. But some of the clients is making channels leak.

Is there a way to see which client is leaking using memory dump and windbg? I cannot use clients IP address because more then one client is coming from the same IP. User identity can be useful but I cannot find connection between leaked service instance and ClaimIdentity used.

1

There are 1 answers

2
Miguel Madero On

The following WinDbg can help you find the leaking channels:

!dumpheap -type <Some WCF Type or yours that you suspect to be leaking>

This will show a list of all of the instances of a particular type. Once you identify the leaking object

!do <object address> 

This will let you inspect the object and it's properties. This way you might be able to get the ClaimId used for this channel

!gcroot 

This will let you know what object is keeping the leaking object in memory and help you fix it. This sounds more useful than actually identifying the client since it seems more likely to be an issue with your server code.

Other useful commands

!gcwhere <Address>
!FindRoots -gen 1
!FindRoots <Address>
!GCHandleLeaks
!eeheap
!dumpheap -stat
!TraverseHeap fileName
!ObjSize
!FindRoots

That said, I've to recommend RedGate's memory profiler. It has come a long way in the last couple of years to identify Memory Leaks. You can get a 14 day trial.