You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Mutex constructor fails with "system cannot open the device or file specified" #1464
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
System.IO.IOException: The system cannot open the device or file specified. : 'PSReadLineHistoryFile_1525368525'
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)
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
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.
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 -CI did can help. I really had it only when I used that parameter.
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 Keys
My 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 these
XProtectPlistConfigData:
Version: 2121
Source: Apple
Install Date: 15/05/2020, 17:41
MRTConfigData:
Version: 1.60
Source: Apple
Install Date: 15/05/2020, 17:46
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\ or Local\). It's unlikely, but can you please check if /tmp on your mac is mapped to somewhere other than private/tmp?
Please close all pwsh sessions (including the sessions opened by VSCode), then check the permission of the folders /tmp/.dotnet and /tmp/.dotnet/shm, to see if their permissions are 777.
If pwsh successfully starts, you should be able to find a sessionxxxxx folder created in /tmp/.dotnet/shm that contains a file named PSReadLineHistoryFile_3946503603. I assume the mutex creation always fails when you starts pwsh, right? If so, please start pwsh by pwsh -noprofile -noninteractive, which won't load PSReadLine. Then please try $mutex = [System.Threading.Mutex]::new($false, "MyM"). If that succeeds, paste the output of dir /tmp/.dotnet/shm -Recurse, and then run $mutex.Dispose().
If the attempt to create a mutex named MyM succeeded, 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 the HResult from the IOException. You can get that IOException instance by looking into $Error[0].Exception.
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 -noninteractive but 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:
MethodInvocationException: Exception calling ".ctor" with "2" argument(s): "The system cannot open the device or file specified. : 'PSReadLineHistoryFile_3946503603'"
FiggyRoll Thanks for providing the additional info!
I just tried removing the /tmp/.dotnet folder, and then start pwsh, and it turned out /tmp/.dotnet folder is automatically created when starting pwsh.
Can you run ls -la /private and copy the mode of the tmp directory? The mode of tmp directory on my mac is drwxrwxrwt. 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 /tmp and on /private/tmp just 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/tmp and chmod +t /private/tmp to fix the permissions and PS now works fine. If I run the $mutex commands you provided above they also complete without issue.
Activity
Stephanevg commentedon Apr 12, 2020
Context:
I was testing Pester v5, and this error threw:
daxian-dbw commentedon Apr 21, 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.
[-]Reporting error[/-][+]Mutex constructor fails with "system cannot open the device or file specified"[/+]Stephanevg commentedon 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.iSazonov commentedon Apr 21, 2020
Did Pester crash before you get the PSRL exception?
daxian-dbw commentedon May 18, 2020
Got a report on the same issue by FiggyRoll:
FiggyRoll commentedon May 19, 2020
Just for some extra info:
Tried the latest beta version of PSReadline today but the issue still persists
daxian-dbw commentedon May 19, 2020
FiggyRoll It sounds this issue happens consistently in your environment (is it?). Could you please do the following to collect some diagnosis information?
/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?/tmp/.dotnetand/tmp/.dotnet/shm, to see if their permissions are777.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().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.FiggyRoll commentedon May 20, 2020
Hi Dongbo Wang (@daxian-dbw)
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'"
iSazonov commentedon May 20, 2020
Maybe reference on a commit in dotnet/roslyn#28529 helps.
daxian-dbw commentedon May 20, 2020
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 run
ls -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.FiggyRoll commentedon May 21, 2020
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.
iSazonov commentedon May 21, 2020
More user friendly error message will be great to have.
daxian-dbw commentedon May 21, 2020
FiggyRoll Thanks for the confirmation. That's great.
Agreed. Opened dotnet/runtime#36823. Hopefully dotnet team can improve the error message.
I will close this issue as resolved.
brainwipe commentedon Nov 13, 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.