internetrush1
Contributor
Contributor

Broke powershell, "The number of WaitHandles must be less than or equal to 64"

Get-VMHost : 4/23/2013 9:41:20 PM    Get-VMHost        The number of WaitHandles must be less than or equal to 64.   
Line:226 char:27
+     $thisHost = Get-VMHost <<<<  -Name $computername
    + CategoryInfo          : NotSpecified: (:) [Get-VMHost], VimException
    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVMHost


Never happened running this script before, we got through a few thousand objects and this only happened when querying through the host-base.

Any idea what causes this and how to fix it?

0 Kudos
9 Replies
LucD
Leadership
Leadership

Never seen that error.

Do you see any additional clues when you do (after the error)

$error[0].Exception | select *

$error[0].Exception.InnerException | select *

Any background jobs (RunAsync) or parallel jobs (Start-Job) in that script ?

What kind of environment are you running this: PowerCLI version, scipt ran on a32/64-bit client, vSPhere & ESXi version...


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
internetrush1
Contributor
Contributor

No threading used, simply passing the cmdlet a name to search for

---

$error[1].exception | select *


ErrorId           : Core_BaseCmdlet_UnknownError
ErrorCategory     : NotSpecified
TargetObject      :
RecommendedAction : Error occured while executing cmdlet: Get-VMHost. Check inner exception for more details.
SessionId         :
ConnectionId      :
Severity          : Error
Message           : 4/23/2013 9:41:56 PM    Get-VMHost        The number of WaitHandles must be less than or equal to 64.   
Data              : {ParameterValues}
InnerException    : System.NotSupportedException: The number of WaitHandles must be less than or equal to 64.
                       at System.Threading.WaitHandle.WaitAny(WaitHandle[] waitHandles, Int32 millisecondsTimeout, Boolean exitContext)
                       at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.ConnectionDispatchHelper.ExecuteRunlist(Dictionary`2 runlist, ParallelConnectionExecutor executor, UidDispatchHelper
                     uidDispatchHelper, List`1 result)
                       at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.ConnectionDispatchHelper.DispatchObjects(ParallelConnectionExecutor executor, UidDispatchHelper uidDispatchHelper, I
                    List`1 connectionList, Boolean isConnectionListExplicit, IList`1 moListFromCmdletParameter, String moListFromCmdletParameterName, Boolean isServerParameterObnOnly)
                       at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.BaseCmdlet.ProcessRecordErrorHandled()
                       at VMware.VimAutomation.ViCore.Util10Ps.BaseCmdlet.BaseCmdlet.ProcessRecordErrorHandled()
TargetSite        : Void ThrowTerminatingError(System.Management.Automation.ErrorRecord)
StackTrace        :    at System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord errorRecord)
HelpLink          :
Source            : System.Management.Automation

----

$error[1].exception.innerexception | select *


Message        : The number of WaitHandles must be less than or equal to 64.
Data           : {}
InnerException :
TargetSite     : Int32 WaitAny(System.Threading.WaitHandle[], Int32, Boolean)
StackTrace     :    at System.Threading.WaitHandle.WaitAny(WaitHandle[] waitHandles, Int32 millisecondsTimeout, Boolean exitContext)
                    at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.ConnectionDispatchHelper.ExecuteRunlist(Dictionary`2 runlist, ParallelConnectionExecutor executor, UidDispatchHelper ui
                 dDispatchHelper, List`1 result)
                    at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.ConnectionDispatchHelper.DispatchObjects(ParallelConnectionExecutor executor, UidDispatchHelper uidDispatchHelper, ILis
                 t`1 connectionList, Boolean isConnectionListExplicit, IList`1 moListFromCmdletParameter, String moListFromCmdletParameterName, Boolean isServerParameterObnOnly)
                    at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.BaseCmdlet.ProcessRecordErrorHandled()
                    at VMware.VimAutomation.ViCore.Util10Ps.BaseCmdlet.BaseCmdlet.ProcessRecordErrorHandled()
HelpLink       :
Source         : mscorlib

0 Kudos
internetrush1
Contributor
Contributor

Hosts ESXi 5.1

Running in x86 windows powershell session (required for DB connection) version 2 on 2008 R2 x64 server

---

Get-PowerCLIVersion


PowerCLI Version
----------------
   VMware vSphere PowerCLI 5.1 Release 1 build 793510
---------------
Snapin Versions
---------------
   VMWare AutoDeploy PowerCLI Component 5.1 build 768137
   VMWare ImageBuilder PowerCLI Component 5.1 build 768137
   VMware vCloud Director PowerCLI Component 1.5 build 793505
   VMware License PowerCLI Component 5.1 build 669840
   VMware vSphere PowerCLI Component 5.1 build 793489

0 Kudos
LucD
Leadership
Leadership

Doesn't make me any wiser I'm afraid.

Perhaps the PowerCLI Dev Team can come up with an explanation, and perhaps a solution.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

internetrush1
Contributor
Contributor

I'm unsure how to proceed with this, a colleague recommended opening up a ticket with VMware. Perhaps i will pursue that path; however, maybe its the instance of powershell that is diong too much, if i thread it to another instance i would reset the job counter.

Thanks!

0 Kudos
LucD
Leadership
Leadership

I tend to agree with your colleague, open a ticket, PowerCLI is supported.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
kneptune
Contributor
Contributor

Not to resurrect an old post, but I ran in to this issue today and thought I'd pass along what I found in case it helps someone else out.

At least in my case, earlier in the day I had run another script with pulled a list of VM hosts out of vCenter and connected to each one, one at a time, and performed some commands.

Several hours later, I reconnected to vCenter and attempted to run a different script, which was pulling all hosts into an array.

Get-VMHost was failing with "...the number of WaitHandles must be less than or equal to 64."

The fix, for me, was forcibly disconnecting all connections to hosts/vCenter.

"Disconnect-VIServer *"


I then re-established my connection to my vCenter server and the script was happy.

0 Kudos
internetrush1
Contributor
Contributor

Hey kneptune,

I found that it is primarily due to using an x86 session for large amounts of transactions and deep pulls from the progrmaming stack.

One thing that i found i was doing is using Pass-by-Reference methodology for a pass-by-copy API such as powershell (i was attempting to keep a single object updated throughout the script) instead of just updating specific portions of the object and passing it back to the copy.

Resolving poor programming or using an x64 instance worked in my case.

0 Kudos
GuilhermeAlves
Enthusiast
Enthusiast

Maybe your vcenter session has forcelly disconnected by someone...That happened to me too!

try disconnecting all sessions and connect again.. it Works for me. 😃

     Disconnect-Viserver * -Force -Confirm:$false

0 Kudos