PoweShell Script execution hangs in Windows Server 2012R2

This topic contains 2 replies, has 2 voices, and was last updated by  kvprasoon 2 months, 4 weeks ago.

  • Author
    Posts
  • #94446

    kvprasoon
    Participant

    One of my script hangs during one of our product installation. Hangs is happening while executing some of the common PowerShell and native ExEs from PowerShell.

    more details in below question which is actually in WindowsServer general Forums.

    https://social.technet.microsoft.com/Forums/windowsserver/en-US/1cbab99f-d601-4ab5-9e8b-fc965c72eafd/oweshell-script-execution-hangs-in-windows-server-2012r2-found-ntdllzwwaitformultipleobjects?forum=winservergen

    we use msdeploy,iisreset,appcmd here during web packages installation, this is the place where it hangs, but hang happens after successful execution of msdeploy.exe. I tried using latest available version of msdeploy, is still hangs some times.

    We have around 7 web packages, hang happens after deploying a package as well as before deploying a package.

    Code logic here.

    Step 1: Test msdeploy exists, if not install it

    Step 2 : iisreset (hangs here sometimes)

    Step 3 : check if the app pool is available, if so Stop-WebAppPool (hangs here sometimes)

    Step 4: install web package using msdeploy

    Step 5: get the app pool state and start if it is not started – (some times hangs here)

    Step 6: do some app pool settings using appcmd.exe (hangs some times after this execution)

    Step 7: some other app pool settings like Set-ItemProperty IIS:\AppPools\$appPoolName -Name recycling.periodicRestart.memory -Value $appPoolRestartMemory

    Step 8 : get the next package and go to Step 1

    Sometimes, hang happens after executing
    netsh http delete urlacl url=$url

    Note: None of the hangs are consistent, each and every time, hang happens in either one place.

    I did procdump analysis of the powershell process and ended up in ntdll!ZwWaitForMultipleObjectsroutine for all hangs.

    same is being shown by the proc explorer threads view as well.

    PFB the hanging handle's stack

    ntdll.dll!ZwWaitForMultipleObjects+0xa
    KERNELBASE.dll!WaitForMultipleObjectsEx+0xed
    clr.dll!GetMetaDataPublicInterfaceFromInternal+0x3a95e
    clr.dll!GetMetaDataPublicInterfaceFromInternal+0x3a7f8
    clr.dll!GetMetaDataPublicInterfaceFromInternal+0x3a5f1
    clr.dll!GetMetaDataPublicInterfaceFromInternal+0x3eeb5
    [Managed to Unmanaged Transition]
    mscorlib.dll!System.Threading.WaitHandle.InternalWaitOne+0x21
    mscorlib.dll!System.Threading.WaitHandle.WaitOne+0x31
    System.Management.Automation.dll!System.Management.Automation.Runspaces.PipelineBase.Invoke+0x34
    Microsoft.PowerShell.ConsoleHost.dll!Microsoft.PowerShell.Executor.ExecuteCommandHelper+0x154
    Microsoft.PowerShell.ConsoleHost.dll!Microsoft.PowerShell.ConsoleHost.DoRunspaceInitialization+0x7ed
    Microsoft.PowerShell.ConsoleHost.dll!Microsoft.PowerShell.ConsoleHost.DoCreateRunspace+0x1d3
    Microsoft.PowerShell.ConsoleHost.dll!Microsoft.PowerShell.ConsoleHost.CreateRunspace+0x49
    Microsoft.PowerShell.ConsoleHost.dll!Microsoft.PowerShell.ConsoleHost.DoRunspaceLoop+0xc3
    Microsoft.PowerShell.ConsoleHost.dll!Microsoft.PowerShell.ConsoleHost.Run+0x14c
    Microsoft.PowerShell.ConsoleHost.dll!Microsoft.PowerShell.ConsoleHost.Start+0x1aa
    Microsoft.PowerShell.ConsoleHost.dll!Microsoft.PowerShell.UnmanagedPSEntry.Start+0x33c
    [Unmanaged to Managed Transition]
    clr.dll!DllCanUnloadNowInternal+0xbe3
    clr.dll!DllCanUnloadNowInternal+0xaa3
    clr.dll!GetMetaDataInternalInterfaceFromPublic+0x1abde
    clr.dll!GetMetaDataInternalInterfaceFromPublic+0x1aa87
    [Managed to Unmanaged Transition]
    mscorlib.dll!System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal+0x80
    mscorlib.dll!System.Reflection.RuntimeMethodInfo.Invoke+0x92
    [Unmanaged to Managed Transition]
    clr.dll!DllCanUnloadNowInternal+0xbe3
    clr.dll!DllCanUnloadNowInternal+0xaa3
    clr.dll!DllCanUnloadNowInternal+0x12f5
    clr.dll!SetRuntimeInfo+0x20b4
    clr.dll!SetRuntimeInfo+0x1c16
    clr.dll!SetRuntimeInfo+0x253d
    clr.dll!SetRuntimeInfo+0x2906
    clr.dll!SetRuntimeInfo+0x276d
    clr.dll!SetRuntimeInfo+0x26ae
    powershell.exe+0x8663
    powershell.exe+0x7c67
    powershell.exe+0xa6cc
    KERNEL32.DLL!BaseThreadInitThunk+0x22
    ntdll.dll!RtlUserThreadStart+0x34

    Any help is appreciated a TON.

  • #94485

    Don Jones
    Keymaster

    Unfortunately, without any consistency, and the fact that you're not actually experiencing a hang in PowerShell itself, this is going to require a much deeper level of debugging than I think I can get into here. I'd have to pull out my low-level process monitors, hook the suspected processes, and really look at their stack traces. That's far, far, far outside the world of "PowerShell," though.

  • #94558

    kvprasoon
    Participant

    Thanks a lot Don,

    I have the process dump of the hung PowerShell, If available, can you suggest that "low level process monitors" for me to dive in.

    One more point to highlight is, all the hangs are happening during actions which are directly or indirectly related to IIS(msdeploy,iisreset,netsh http delete urlacl url=$url,appcmd and WebAdministration cmdlets).

You must be logged in to reply to this topic.