2019-09-18

An SPPerformanceCounter was not properly disposed

I came across an unexpected error in ULS on my SharePoint 2013 development farm:
An SPPerformanceCounter was not properly disposed.  This could cause excessive memory use.

I've noticed it happens immediately after Health Analysis Job (Hourly, Distributed Cache, All Servers) timer job has executed. In the ULS I also saw that the following rules are being executed by aforementioned timer job:

  • Microsoft.SharePoint.Administration.Health.SPDistributedCacheHostDown
  • Microsoft.SharePoint.Administration.Health.SPDistributedCacheHostFirewallSettingsIncorrect
  • Microsoft.SharePoint.Administration.Health.SPDistributedCacheObjectEvicted
  • Microsoft.SharePoint.Administration.Health.SPDistributedCacheHostApproachingThrottling
I've reflected Microsoft.SharePoint.Health.dll in order to map rules to the descriptions in CA. Each of the classes mentioned above has a property named Summary. In the getter of the property there's a key to resource, such as HealthRule_Summary_SPDistributedCacheObjectEvicted for SPDistributedCacheObjectEvicted class. Next I reflected Microsoft.SharePoint.intl.dll and searched for the keys in Microsoft.SharePoint.resources of the assembly. This is how mapping between rules (classes) and descriptions looks like:

  • Microsoft.SharePoint.Administration.Health.SPDistributedCacheHostDown - One of the cache hosts in the cluster is down.
  • Microsoft.SharePoint.Administration.Health.SPDistributedCacheHostFirewallSettingsIncorrect - Firewall client settings on the cache host are incorrect.
  • Microsoft.SharePoint.Administration.Health.SPDistributedCacheObjectEvicted - Cached objects have been evicted.
  • Microsoft.SharePoint.Administration.Health.SPDistributedCacheHostApproachingThrottling - The Current server is running low on memory.
Then I opened Central Administration (Monitoring > Review rule definitions) and ran the rules one by one while monitoring ULS real time. I found the offending rule in Microsoft.SharePoint.Administration.Health.SPDistributedCacheObjectEvicted

Piece of code which is causing the issue is located in Microsoft.SharePoint.dll assembly, namely by the method Microsoft.SharePoint.DistributedCaching.Utilities.SPDistributedCacheHealthRulesHelper.GetTotalObjectsEvicted(). Line 149 is causing the error:
num = (uint) new SPPerformanceCounter("AppFabric Caching:Host", "Total Evicted Objects").NextValue();

My development farm is on SP1 level. Since I can't upgrade the farm a newer version, because production farm is on that level, I had only two options to resolve the issue:
  1. Treat it as a false positive, i.e. ignore the error.
  2. Disable the rule in CA.
I chose option two. I disabled the rule in CA and ran the timer job again. There were no unexpected errors in ULS any more.

No comments:

Post a Comment