Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.Threading.WaitHandleCannotBeOpenedException: A WaitHandle with system-wide name 'PSReadLineHistoryFile_1117427230' cannot be created. #2410

Closed
rjmholt opened this issue Apr 29, 2021 · 11 comments
Labels
Issue-Triaged It indicates an issue was triaged Needs-More Investigation Initial investigation is done, but need to follow up.

Comments

@rjmholt
Copy link
Contributor

rjmholt commented Apr 29, 2021

> Start-DevPowerShell
WARNING: Start-DevPowerShell -NoNewWindow is currently implied in PowerShellCore edition https://github.com/PowerShell/PowerShell/issues/1543
PS /Users/rjmholt/Documents/Dev/Microsoft/PowerShell>
Oops, something went wrong.
Please report this bug with ALL the details below, including both the 'Environment' and 'Exception' sections.
Please report on GitHub: https://github.com/PowerShell/PSReadLine/issues/new?template=Bug_Report.md
Thank you!

Environment

PSReadLine: 2.1.0
PowerShell: 7.2.0-preview.5
OS: Darwin 20.3.0 Darwin Kernel Version 20.3.0: Thu Jan 21 00:06:51 PST 2021; root:xnu-7195.81.3~1/RELEASE_ARM64_T8101
BufferWidth: 134
BufferHeight: 63

Last 0 Keys


Exception

System.Threading.WaitHandleCannotBeOpenedException: A WaitHandle with system-wide name 'PSReadLineHistoryFile_1117427230' cannot be created. A WaitHandle of a different type might have the same name.
   at System.Threading.Mutex.CreateMutexCore(Boolean initiallyOwned, String name, Boolean& createdNew)
   at System.Threading.Mutex..ctor(Boolean initiallyOwned, String name)
   at Microsoft.PowerShell.PSConsoleReadLine.DelayedOneTimeInitialize()
   at Microsoft.PowerShell.PSConsoleReadLine.Initialize(Runspace runspace, EngineIntrinsics engineIntrinsics)
   at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics, CancellationToken cancellationToken)

Steps to reproduce

  1. Start-DevPowerShell
  2. Await prompt

Expected behavior

Get prompt

Actual behavior

Throws in PSRL due to wait handle issue and falls back to default readline.

@ghost ghost added the Needs-Triage 🔍 It's a new issue that core contributor team needs to triage. label Apr 29, 2021
@iSazonov
Copy link

I guess it can not create a temp file for the mutex.

@rjmholt
Copy link
Contributor Author

rjmholt commented Apr 29, 2021

Exception             :
    Type           : System.Management.Automation.MethodInvocationException
    ErrorRecord    :
        Exception             :
            Type    : System.Management.Automation.ParentContainsErrorRecordException
            Message : Exception calling "ReadLine" with "2" argument(s): "A WaitHandle with system-wide name
'PSReadLineHistoryFile_1117427230' cannot be created. A WaitHandle of a different type might have the same name."
            HResult : -2146233087
        CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordException
        FullyQualifiedErrorId : WaitHandleCannotBeOpenedException
        InvocationInfo        :
            ScriptLineNumber : 4
            OffsetInLine     : 5
            HistoryId        : -1
            ScriptName       : /Users/rjmholt/Documents/Dev/Microsoft/PowerShell/src/powershell-unix/bin/Debug/net6.0/osx-arm64/p
ublish/Modules/PSReadLine/PSReadLine.psm1
            Line             : [Microsoft.PowerShell.PSConsoleReadLine]::ReadLine($host.Runspace, $ExecutionContext)

            PositionMessage  : At /Users/rjmholt/Documents/Dev/Microsoft/PowerShell/src/powershell-unix/bin/Debug/net6.0/osx-arm64/pu
blish/Modules/PSReadLine/PSReadLine.psm1:4 char:5
                               +     [Microsoft.PowerShell.PSConsoleReadLine]::ReadLine($host.Runspace …
                               +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            PSScriptRoot     :
/Users/rjmholt/Documents/Dev/Microsoft/PowerShell/src/powershell-unix/bin/Debug/net6.0/osx-arm64/publish/Modules/PSReadLine
            PSCommandPath    : /Users/rjmholt/Documents/Dev/Microsoft/PowerShell/src/powershell-unix/bin/Debug/net6.0/osx-arm64/p
ublish/Modules/PSReadLine/PSReadLine.psm1
            CommandOrigin    : Internal
        ScriptStackTrace      : at PSConsoleHostReadLine, /Users/rjmholt/Documents/Dev/Microsoft/PowerShell/src/powershell-unix/bin/D
ebug/net6.0/osx-arm64/publish/Modules/PSReadLine/PSReadLine.psm1: line 4
    TargetSite     :
        Name          : ConvertToMethodInvocationException
        DeclaringType : System.Management.Automation.ExceptionHandlingOps, System.Management.Automation, Version=7.2.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35
        MemberType    : Method
        Module        : System.Management.Automation.dll
    StackTrace     :
   at System.Management.Automation.ExceptionHandlingOps.ConvertToMethodInvocationException(Exception exception, Type typeToThrow,
String methodName, Int32 numArgs, MemberInfo memberInfo) in
/Users/rjmholt/Documents/Dev/Microsoft/PowerShell/src/System.Management.Automation/engine/runtime/Operations/MiscOps.cs:line 2067
   at CallSite.Target(Closure , CallSite , Type , Object , Object )
   at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
   at System.Management.Automation.Interpreter.DynamicInstruction`4.Run(InterpretedFrame frame) in /Users/rjmholt/Documents/Dev/Micro
soft/PowerShell/src/System.Management.Automation/engine/interpreter/DynamicInstructions.Generated.cs:line 192
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) in /Users/rjmholt/Document
s/Dev/Microsoft/PowerShell/src/System.Management.Automation/engine/interpreter/ControlFlowInstructions.cs:line 358
    Message        : Exception calling "ReadLine" with "2" argument(s): "A WaitHandle with system-wide name
'PSReadLineHistoryFile_1117427230' cannot be created. A WaitHandle of a different type might have the same name."
    Data           : System.Collections.ListDictionaryInternal
    InnerException :
        Type       : System.Threading.WaitHandleCannotBeOpenedException
        TargetSite :
            Name          : CreateMutexCore
            DeclaringType : System.Threading.Mutex
            MemberType    : Method
            Module        : System.Private.CoreLib.dll
        StackTrace :
   at System.Threading.Mutex.CreateMutexCore(Boolean initiallyOwned, String name, Boolean& createdNew)
   at System.Threading.Mutex..ctor(Boolean initiallyOwned, String name)
   at Microsoft.PowerShell.PSConsoleReadLine.DelayedOneTimeInitialize()
   at Microsoft.PowerShell.PSConsoleReadLine.Initialize(Runspace runspace, EngineIntrinsics engineIntrinsics)
   at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics, CancellationToken
cancellationToken)
   at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics)
   at CallSite.Target(Closure , CallSite , Type , Object , Object )
        Message    : A WaitHandle with system-wide name 'PSReadLineHistoryFile_1117427230' cannot be created. A WaitHandle of a
different type might have the same name.
        Source     : System.Private.CoreLib
        HResult    : -2146233044
    Source         : System.Management.Automation
    HResult        : -2146233087
CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
FullyQualifiedErrorId : WaitHandleCannotBeOpenedException
InvocationInfo        :
    ScriptLineNumber : 4
    OffsetInLine     : 5
    HistoryId        : -1
    ScriptName       : /Users/rjmholt/Documents/Dev/Microsoft/PowerShell/src/powershell-unix/bin/Debug/net6.0/osx-arm64/publish/M
odules/PSReadLine/PSReadLine.psm1
    Line             : [Microsoft.PowerShell.PSConsoleReadLine]::ReadLine($host.Runspace, $ExecutionContext)

    PositionMessage  : At /Users/rjmholt/Documents/Dev/Microsoft/PowerShell/src/powershell-unix/bin/Debug/net6.0/osx-arm64/publish/Mo
dules/PSReadLine/PSReadLine.psm1:4 char:5
                       +     [Microsoft.PowerShell.PSConsoleReadLine]::ReadLine($host.Runspace …
                       +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    PSScriptRoot     :
/Users/rjmholt/Documents/Dev/Microsoft/PowerShell/src/powershell-unix/bin/Debug/net6.0/osx-arm64/publish/Modules/PSReadLine
    PSCommandPath    : /Users/rjmholt/Documents/Dev/Microsoft/PowerShell/src/powershell-unix/bin/Debug/net6.0/osx-arm64/publish/M
odules/PSReadLine/PSReadLine.psm1
    CommandOrigin    : Internal
ScriptStackTrace      : at PSConsoleHostReadLine, /Users/rjmholt/Documents/Dev/Microsoft/PowerShell/src/powershell-unix/bin/Debug/net
6.0/osx-arm64/publish/Modules/PSReadLine/PSReadLine.psm1: line 4

@daxian-dbw
Copy link
Member

This is a duplicate of #1464. It's likely a permission issue to /private/tmp. @rjmholt, please take a look at #1464 (comment) to see if that fix your problem too.

@daxian-dbw daxian-dbw added Needs-Author Feedback and removed Needs-Triage 🔍 It's a new issue that core contributor team needs to triage. labels Apr 29, 2021
@rjmholt
Copy link
Contributor Author

rjmholt commented Apr 29, 2021

/private/tmp seems to have full permissions according to stat but not sure about pwsh:

image

image

@rjmholt
Copy link
Contributor Author

rjmholt commented Apr 29, 2021

Also, I've been running PSRL without issue in PS 7.1.3. It's in dev builds where it fails.

@daxian-dbw
Copy link
Member

Wait a minute. The error message you had is different from the /private/tmp permission-issue one.

A WaitHandle with system-wide name 'PSReadLineHistoryFile_1117427230' cannot be created. A WaitHandle of a different type might have the same name.

The permission-issue ones:

The system cannot open the device or file specified.

I never saw this failure before. Can you collect some diagnostic information by following the instructions described in #1464 (comment)?

Can you also try opening the 7.1.3 pwsh within your PS 7.1.3 session?

@rjmholt
Copy link
Contributor Author

rjmholt commented Apr 30, 2021

Location of the /tmp link:

PS /Users/rjmholt/Documents/Dev/Microsoft/PowerShell> readlink /tmp
private/tmp

Permissions on mutex dir:

rjmholt@Roberts-Mac-mini ~ % stat -f '%A' /tmp/.dotnet
777
rjmholt@Roberts-Mac-mini ~ % stat -f '%A' /tmp/.dotnet/shm
777

Results of mutex creation:

> ./src/powershell-unix/bin/Debug/net6.0/osx-arm64/publish/pwsh -noprofile -noninteractive                                            PowerShell 7.2.0-preview.5-20-g8f8ddc3fb76a03dad93f5664314c2795dd69f390                                                               Copyright (c) Microsoft Corporation.                                                                                                                                                                                                                                        https://aka.ms/powershell                                                                                                             Type 'help' to get help.                                                                                                                                                                                                                                                    PS /Users/rjmholt/Documents/Dev/Microsoft/PowerShell> $mutex = [system.threading.mutex]::new($false, "MyM")                           PS /Users/rjmholt/Documents/Dev/Microsoft/PowerShell> dir /tmp/.dotnet/shm -recurse                                                                                                                                                                                             Directory: /tmp/.dotnet/shm
UnixMode   User             Group                 LastWriteTime           Size Name
--------   ----             -----                 -------------           ---- ----
drwxrwxrwx rjmholt          wheel               4/30/2021 07:13             96 session778
drwxrwxrwx rjmholt          wheel               4/30/2021 09:33            128 session779

    Directory: /tmp/.dotnet/shm/session778

UnixMode   User             Group                 LastWriteTime           Size Name
--------   ----             -----                 -------------           ---- ----
-rw-rw-rw- rjmholt          wheel               4/30/2021 07:13           4096 PSReadLineHistoryFile_1117427230

    Directory: /tmp/.dotnet/shm/session779

UnixMode   User             Group                 LastWriteTime           Size Name
--------   ----             -----                 -------------           ---- ----
-rw-rw-rw- rjmholt          wheel               4/30/2021 09:33          16384 MyM
-rw-rw-rw- rjmholt          wheel               4/30/2021 09:31           4096 PSReadLineHistoryFile_1117427230

PS /Users/rjmholt/Documents/Dev/Microsoft/PowerShell> $mutex.Dispose()

The second mutex creation succeeds.

Opening pwsh within pwsh also works fine.

@rjmholt
Copy link
Contributor Author

rjmholt commented Apr 30, 2021

Just to follow up, when I rebuilt PS to target osx-x64 this went away. It was only running osx-arm64 that this was an issue.

@daxian-dbw
Copy link
Member

That is really strange ... may be a mutex issue in .NET

@daxian-dbw daxian-dbw added Issue-Triaged It indicates an issue was triaged Needs-More Investigation Initial investigation is done, but need to follow up. and removed Needs-Attention 👋 labels May 1, 2021
@daxian-dbw
Copy link
Member

PowerShell doesn't support (release) the arm64 package for macOS today, even though our build script allows osx-arm64 as the runtime value. Given that, I don't think there will be investigation to this issue until we're considering supporting arm64 for macOS. So I will close this issue for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Triaged It indicates an issue was triaged Needs-More Investigation Initial investigation is done, but need to follow up.
Projects
None yet
Development

No branches or pull requests

3 participants