Simultaneous pwsh instance start Mutex.CreateMutexCore IOException race condition
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Start at PSConsoleReadLine.DelayedOneTimeInitialize(), following the Mutex constructor and the PSReadLineHistoryFile name generation shown in the stack trace. Reproduce simultaneous pwsh launches, inspect how concurrent instances contend for the mutex, and verify that restored tabs no longer display the IOException.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Environment
PSReadLine: 2.1.0
PowerShell: 7.1.3
OS: Darwin 20.5.0 Darwin Kernel Version 20.5.0: Sat May 8 05:10:33 PDT 2021; root:xnu-7195.121.3~9/RELEASE_X86_64
BufferWidth: 176
BufferHeight: 91
Exception report
iTerm session 3:
System.IO.IOException: The system cannot open the device or file specified. : 'PSReadLineHistoryFile_2886463743'
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)
iTerm session 4:
System.IO.IOException: The system cannot open the device or file specified. : 'PSReadLineHistoryFile_2886463743'
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
(Steps that shouldn't matter: My macbook was asleep in clamshell mode, I unplugged the display connections, and the OS crashed. I logged in and submitted the bug report to Apple, again.)
I saw this message on two tabs when iTerm2 was trying to restore a terminal window with four tab. The first two tabs did not have any error.
iTerm session restore caused 4 pwsh instances to launch at the same time, and got these two crashes from different pwsh instances.
Expected behavior
Launching multiple pwsh instances at the exact same time should not show error.
Actual behavior
Tabs 3 and 4 each showed the exception message above.
Running some debug commands, there are a lot of PSReadLineHistoryFile_2886463743 files created at nearly the exact same millisecond:
➜ ~ gci -r /tmp/.dotnet/shm
Directory: /tmp/.dotnet/shm
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 7/8/2021 10:59 AM session1999
d---- 7/8/2021 12:55 PM session5595
d---- 7/8/2021 10:15 AM session705
d---- 7/8/2021 10:15 AM session710
d---- 7/8/2021 10:15 AM session715
d---- 7/8/2021 10:15 AM session721
Directory: /tmp/.dotnet/shm/session715
Mode LastWriteTime Length Name
---- ------------- ------ ----
----- 7/8/2021 10:15 AM 4096 PSReadLineHistoryFile_2886463743
Directory: /tmp/.dotnet/shm/session705
Mode LastWriteTime Length Name
---- ------------- ------ ----
----- 7/8/2021 10:15 AM 4096 PSReadLineHistoryFile_2886463743
Directory: /tmp/.dotnet/shm/session5595
Mode LastWriteTime Length Name
---- ------------- ------ ----
----- 7/8/2021 12:44 PM 4096 PSReadLineHistoryFile_2886463743
----- 7/8/2021 12:55 PM 4096 PSReadLineHistoryFile_3946503603
Directory: /tmp/.dotnet/shm/session1999
Mode LastWriteTime Length Name
---- ------------- ------ ----
----- 7/8/2021 10:59 AM 4096 PSReadLineHistoryFile_2886463743
Directory: /tmp/.dotnet/shm/session721
Mode LastWriteTime Length Name
---- ------------- ------ ----
----- 7/8/2021 10:15 AM 4096 PSReadLineHistoryFile_2886463743
Directory: /tmp/.dotnet/shm/session710
Mode LastWriteTime Length Name
---- ------------- ------ ----
----- 7/8/2021 10:15 AM 4096 PSReadLineHistoryFile_2886463743
➜ ~ gci -r -file /tmp/.dotnet/shm | % { $_.LastWriteTime.ToString("MM/dd/yyyy hh:mm:ss.ffffff tt") } | sort-object
07/08/2021 10:15:57.403067 AM
07/08/2021 10:15:57.403165 AM
07/08/2021 10:15:57.425071 AM
07/08/2021 10:15:57.425950 AM
07/08/2021 10:59:23.698350 AM
07/08/2021 12:44:43.666927 PM
07/08/2021 12:55:35.784985 PM
My 2 cents:
- This is not a duplicate of #1464. My macOS permissions on /private/tmp are fine, and manually opening a pwsh instances always works.
- Changing the exception message in dotnet/runtime#36823 won't fix the problem of not showing exception message.
- Whatever code that is in charge of picking mutex names is using the same mutex name.
- On Windows, I've seen
System.Threading.Mutexthrow occasionally if the mutex name is contended.- The .ctor() documentation says
IOExceptioncan happen when some other error happens.
- The .ctor() documentation says
- Maybe pwsh could make the mutex name more unique across instances?
- Maybe pwsh could use a retry loop around mutex code that sometimes throws?
- Ngôn ngữ chính
- C#
- Star
- 4.4k
- Fork
- 341
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của PowerShell/PSReadLine
-
Needs-Triage :mag:
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
PowerShell/PSReadLine#5205 ·
-
Needs-Triage :mag:
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
PowerShell/PSReadLine#5195 ·
-
Needs-Triage :mag:
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
PowerShell/PSReadLine#5121 ·
-
Needs-Triage :mag:
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
PowerShell/PSReadLine#5045 ·
-
Area-CommandHelp Issue-Enhancement
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 68/100
PowerShell/PSReadLine#3470 · 3 reaction ·
Tất cả issue của PowerShell/PSReadLine
Issue tương tự
-
bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 75/100
sillsdev/languageforge-lexbox#2665 ·
-
bug documentation frontend
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
azurenoops/spin_agent#975 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
-
:watch: Not Triaged 11.0 fundamentals/subsvc
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 92/100
dotnet/AspNetCore.Docs#37699 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
SubtitleEdit/subtitleedit#15108 · 1 bình luận ·