5

I have experienced increase of invalid handles in System process (Windows Server 2008R2 x64). The amount is approximately 1,000,000 per week.

According to Process Explorer the handle type is file. From the task manager it seems the memory is not assigned to any of the processes but graph shows high (and growing) physical memory usage.

How to avoid or release invalid system handles?

squillman
  • 38,163
nkula
  • 71

2 Answers2

2

I was not able to find the root cause yet but I figured out how to clean it up.

When I copied one of the files to analyse it I found out that the invalid handle was "reused" or "refreshed" and properly closed. It seems that operations on file like open, copy, delete fix the handle. So I created the powershell script that first get the list of handles using util Handle v3.51 and open affected files. After first run the number of handles descreased, physical memory usage started to decrease as well and after a few runs it looks ok. The clean up is scheduled nightly.

$handlesLog = .\handle.exe -p 4  # 4 is System process id

foreach ($line in $handlesLog)
{   
    if ($line -match "<here is the pattern of affected  files>")
    {
        $fileToCopy = <full path to the file>

        if ([System.IO.File]::Exists($fileToCopy))
        {
            try
            {
              $fileStr = New-Object  System.IO.FileStream($fileToCopy,[System.IO.FileMode]::Open, [System.IO.FileAccess]::Read)
            }
            finally
            {
               $fileStr.Close()
               $fileStr.Dispose()
            }
        }
    }
}
nkula
  • 71
0

Do you have offline files turned on? You can disable them in Control Panel > Sync Center > Disable Offline Files (on the left-hand side). Maybe the server is trying to download an offline copy of the files, so it's not closing the handles properly. Just a shot in the dark.