Repository navigation
Mutex constructor fails with "system cannot open the device or file specified" #1464
Description
Activity
- ghost addedNeeds-Triage 🔍It's a new issue that core contributor team needs to triage.It's a new issue that core contributor team needs to triage.
on Apr 12, 2020 Context:
I was testing Pester v5, and this error threw:
PS /Users/stephanevg/Code/PSHTML> $e = invoke-pester -Path ./link.tests.ps1 -CI Get-Item: /Users/stephanevg/.local/share/powershell/Modules/Pester/5.0.0/Pester.psm1:793 Line | 793 | $i = Get-Item $p | ~~~~~~~~~~~ | Cannot find path '/Users/stephanevg/Code/PSHTML/link.tests.ps1' because it does not exist. System.Management.Automation.ParameterBindingValidationException: Cannot bind argument to parameter 'Path' because it is null. at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception) at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) at Invoke-Pester<End>, /Users/stephanevg/.local/share/powershell/Modules/Pester/5.0.0/Pester.psm1: line 798 at <ScriptBlock>, <No file>: line 1 bash-3.2$ pwsh PowerShell 7.0.0 Copyright (c) Microsoft Corporation. All rights reserved. https://aka.ms/powershell Type 'help' to get help. PS /Users/stephanevg/Code/ansible-lab/Roles> Oops, something went wrong. Please report this bug with the details below. Report on GitHub: https://github.com/PowerShell/PSReadLine/issues/new
- addedNeeds-More InvestigationInitial investigation is done, but need to follow up.Initial investigation is done, but need to follow up.and removedNeeds-Triage 🔍It's a new issue that core contributor team needs to triage.It's a new issue that core contributor team needs to triage.
on Apr 20, 2020 It makes me sad to see this happen on PSReadLine 2.0.0
☹️
I saw this reported before and thought #1061 would resolve the issue, but now obviously it didn't.
Stéphane (@Stephanevg) does it happen to you consistently? It's super hard for me to get a repro.- changed the title
[-]Reporting error[/-][+]Mutex constructor fails with "system cannot open the device or file specified"[/+]on Apr 21, 2020 Hi Dongbo Wang (@daxian-dbw)
Thanks for asking. Actually, I only had it twice.
Since, I didn't encountered the issue anymore (But I was busy with some other stuff).This was also while testing a early release of Pester v5 (RC1 to be precise).
It could be that that some of the internals there were not completley polished or so.
Perhaps looking in the code of Pester v5 rc1 and what that-CIdid can help. I really had it only when I used that parameter.Did Pester crash before you get the PSRL exception?
Got a report on the same issue by FiggyRoll:
The issue has returned with the exact same error message
Exception
System.IO.IOException: The system cannot open the device or file specified. : 'PSReadLineHistoryFile_3946503603' 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)Other details from the error
### Environment PSReadLine: 2.0.0 PowerShell: 7.0.1 OS: Darwin 19.4.0 Darwin Kernel Version 19.4.0: Wed Mar 4 22:28:40 PST 2020; root:xnu-6153.101.6~15/RELEASE_X86_64 Last 0 KeysMy mac is up to date and I'm not aware of any additional updates that have been installed in the last few days. This was working up until at least Wednesday last week.
To reproduce I just run pwsh from terminal on my mac. I noticed the issue this morning when opening a script in vscode, and then tested just opening powershell in terminal and the issue appeared.
I have powershell installed using brew, and up until this morning was on 7.0.0, I have upgraded to 7.1.0 this morning using 'brew cask upgrade powershell' but the issue persists. I did also have powershell-preview installed using brew which I have now removed, but still have the error.
UPDATE:
Checking installed updates on my mac and the only changes I can see are theseXProtectPlistConfigData: Version: 2121 Source: Apple Install Date: 15/05/2020, 17:41 MRTConfigData: Version: 1.60 Source: Apple Install Date: 15/05/2020, 17:46Just for some extra info:
Tried the latest beta version of PSReadline today but the issue still persists
FiggyRoll It sounds this issue happens consistently in your environment (is it?). Could you please do the following to collect some diagnosis information?
- The mutex name is used to create a file at path
/tmp/.dotnet/shm/<session>/<mutexName>, where<session>is global/local<sessionId>, and<mutexName>is the name minus the session prefix (Global\orLocal\). It's unlikely, but can you please check if/tmpon your mac is mapped to somewhere other thanprivate/tmp? - Please close all pwsh sessions (including the sessions opened by VSCode), then check the permission of the folders
/tmp/.dotnetand/tmp/.dotnet/shm, to see if their permissions are777. - If pwsh successfully starts, you should be able to find a
sessionxxxxxfolder created in/tmp/.dotnet/shmthat contains a file namedPSReadLineHistoryFile_3946503603. I assume the mutex creation always fails when you starts pwsh, right? If so, please start pwsh bypwsh -noprofile -noninteractive, which won't loadPSReadLine. Then please try$mutex = [System.Threading.Mutex]::new($false, "MyM"). If that succeeds, paste the output ofdir /tmp/.dotnet/shm -Recurse, and then run$mutex.Dispose(). - If the attempt to create a mutex named
MyMsucceeded, please try$mutex = [System.Threading.Mutex]::new($false, "PSReadLineHistoryFile_3946503603")just like what PSReadLine does, and see if that fail. If that fails, please get theHResultfrom theIOException. You can get thatIOExceptioninstance by looking into$Error[0].Exception.
- The mutex name is used to create a file at path
Thanks for the reply, I really appreciate you taking the time to look into this. Going through the steps and found an issue on step 1, which might be the cause of the problems?
There is no /tmp/.dotnet directory on my mac. (/tmp is mapped to private/tmp)
Ive tried step 3 as well just to see what errors I am given and can confirm that PS does load correctly using
pwsh -noprofile -noninteractivebut then when I run thew following command:
$mutex = [System.Threading.Mutex]::new($false, "MyM")that fails and gives the following error:MethodInvocationException: Exception calling ".ctor" with "2" argument(s): "The system cannot open the device or file specified. : 'MyM'"
Just for completeness I also attempted the command that PSReadLine does and get the following:
$mutex = [System.Threading.Mutex]::new($false, "PSReadLineHistoryFile_3946503603")MethodInvocationException: Exception calling ".ctor" with "2" argument(s): "The system cannot open the device or file specified. : 'PSReadLineHistoryFile_3946503603'"
Maybe reference on a commit in dotnet/roslyn#28529 helps.
FiggyRoll Thanks for providing the additional info!
I just tried removing the/tmp/.dotnetfolder, and then startpwsh, and it turned out/tmp/.dotnetfolder is automatically created when startingpwsh.
Can you runls -la /privateand copy the mode of thetmpdirectory? The mode oftmpdirectory on my mac isdrwxrwxrwt. I suspect that your tmp folder doesn't have the permission for the dotnet runtime to create those folders.Dongbo Wang (@daxian-dbw) I think you have found the issue! I checked the permissions on
/tmpand on/private/tmpjust to be thorough and both showed 755 for the permissions.Did some quick googling just to make sure that the normal permissions should be 1777, couldn't find anything definitive but the general consensus seems to be that is correct. So not sure why the permissions on mine would have changed (had issues with brew a while ago so possibly when fixing that)
Anyway,
chmod 777 /private/tmpandchmod +t /private/tmpto fix the permissions and PS now works fine. If I run the$mutexcommands you provided above they also complete without issue.Thanks for your help with this, much appreciated.
Reacted by Damian RivasReacted by Damian RivasMore user friendly error message will be great to have.
FiggyRoll Thanks for the confirmation. That's great.
More user friendly error message will be great to have.
Agreed. Opened dotnet/runtime#36823. Hopefully dotnet team can improve the error message.
I will close this issue as resolved.- addedResolution-AnsweredQuestion is answeredQuestion is answeredand removedNeeds-More InvestigationInitial investigation is done, but need to follow up.Initial investigation is done, but need to follow up.
on May 21, 2020 - pinned this issue
on May 21, 2020 Please keep closed, this is for others landing here.
This error message is also thrown when
/tmpis full. You can check how much is free using:df -k /tmpIf
Availableis 0 orUse%is 100, then/tmpis full.How you then go about cleaning it depends on your use case. To remove any file that's older than 10 days:
sudo find /tmp -type f -atime +10 -deleteApologies for pinging this thread, it's the top result in Google for the error as a search term.
Reacted by Dongbo Wang, oneplusTree, Chanjung Kim, Ted Chambers, Eduardo Velarde and David DennisonReacted by David Dennison- addedissue-mutexThe mutex creation issue on macOSThe mutex creation issue on macOS
on Aug 7, 2023
Hi, Just beeing a good citizen, and doing as the console is asking me to do:
bash-3.2$ pwsh
PowerShell 7.0.0
Copyright (c) Microsoft Corporation. All rights reserved.
https://aka.ms/powershell
Type 'help' to get help.
PS /Users/stephanevg/Code/ansible-lab/Roles>
Oops, something went wrong. Please report this bug with the details below.
Report on GitHub: https://github.com/PowerShell/PSReadLine/issues/new
Environment
PSReadLine: 2.0.0
PowerShell: 7.0.0
OS: Darwin 19.3.0 Darwin Kernel Version 19.3.0: Thu Jan 9 20:58:23 PST 2020; root:xnu-6153.81.5~1/RELEASE_X86_64
Exception