8000 Do not crash when can't create telemetry mutex. by gukoff · Pull Request #15574 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Do not crash when can't create telemetry mutex. #15574

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

Merged
merged 1 commit into from
Jun 14, 2021

Conversation

gukoff
Copy link
Contributor
@gukoff gukoff commented Jun 14, 2021

PR Summary

Do not stop powershell when can't create telemetry mutex.

PR Context

Currently powershell crashes on startup if it can't create an instance of new Mutex. It might happen if there's no space on the disk, or if the current user doesn't have permissions to the tmp folder.

Powershell crashes with the following error:

Error: failed to execute "pwsh": Process terminated. The type initializer for 'Microsoft.PowerShell.Telemetry.ApplicationInsightsTelemetry' threw an exception.
   at System.Environment.FailFast(System.String, System.Exception)
   at Microsoft.PowerShell.UnmanagedPSEntry.Start(System.String[], Int32)
   at Microsoft.PowerShell.ManagedPSEntry.Main(System.String[])
System.TypeInitializationException: The type initializer for 'Microsoft.PowerShell.Telemetry.ApplicationInsightsTelemetry' threw an exception.
 ---> System.IO.IOException: The system cannot open the device or file specified. : 'CreateUniqueUserId'
   at System.Threading.Mutex.CreateMutexCore(Boolean initiallyOwned, String name, Boolean& createdNew)
   at System.Threading.Mutex..ctor(Boolean initiallyOwned, String name)
   at Microsoft.PowerShell.Telemetry.ApplicationInsightsTelemetry.GetUniqueIdentifier() in /PowerShell/src/System.Management.Automation/utils/Telemetry.cs:line 802
   at Microsoft.PowerShell.Telemetry.ApplicationInsightsTelemetry..cctor() in /PowerShell/src/System.Management.Automation/utils/Telemetry.cs:line 548
   --- End of inner exception stack trace ---
   at Microsoft.PowerShell.Telemetry.ApplicationInsightsTelemetry.SendPSCoreStartupTelemetry(String mode) in /PowerShell/src/System.Management.Automation/utils/Telemetry.cs:line 656
   at Microsoft.PowerShell.ConsoleHost.Start(String bannerText, String helpText) in /PowerShell/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs:line 248
   at Microsoft.PowerShell.UnmanagedPSEntry.Start(String[] args, Int32 argc) in /PowerShell/src/Microsoft.PowerShell.ConsoleHost/host/msh/ManagedEntrance.cs:line 99

This exception is thrown from Mutex ctor and isn't properly handled. This change fixes it.

PR Checklist

@ghost ghost assigned rjmholt Jun 14, 2021
@gukoff gukoff changed the title [WIP] Do not stop powershell when can't create telemetry mutex. [WIP] Do not crash when can't create telemetry mutex. Jun 14, 2021
@gukoff gukoff changed the title [WIP] Do not crash when can't create telemetry mutex. Do not crash when can't create telemetry mutex. Jun 14, 2021
@gukoff gukoff marked this pull request as ready for review June 14, 2021 10:57
Currently powershell crashes if there's no space on the disk with the following error:

```
Error: failed to execute "pwsh": Process terminated. The type initializer for 'Microsoft.PowerShell.Telemetry.ApplicationInsightsTelemetry' threw an exception.
   at System.Environment.FailFast(System.String, System.Exception)
   at Microsoft.PowerShell.UnmanagedPSEntry.Start(System.String[], Int32)
   at Microsoft.PowerShell.ManagedPSEntry.Main(System.String[])
System.TypeInitializationException: The type initializer for 'Microsoft.PowerShell.Telemetry.ApplicationInsightsTelemetry' threw an exception.
 ---> System.IO.IOException: The system cannot open the device or file specified. : 'CreateUniqueUserId'
   at System.Threading.Mutex.CreateMutexCore(Boolean initiallyOwned, String name, Boolean& createdNew)
   at System.Threading.Mutex..ctor(Boolean initiallyOwned, String name)
   at Microsoft.PowerShell.Telemetry.ApplicationInsightsTelemetry.GetUniqueIdentifier() in /PowerShell/src/System.Management.Automation/utils/Telemetry.cs:line 802
   at Microsoft.PowerShell.Telemetry.ApplicationInsightsTelemetry..cctor() in /PowerShell/src/System.Management.Automation/utils/Telemetry.cs:line 548
   --- End of inner exception stack trace ---
   at Microsoft.PowerShell.Telemetry.ApplicationInsightsTelemetry.SendPSCoreStartupTelemetry(String mode) in /PowerShell/src/System.Management.Automation/utils/Telemetry.cs:line 656
   at Microsoft.PowerShell.ConsoleHost.Start(String bannerText, String helpText) in /PowerShell/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs:line 248
   at Microsoft.PowerShell.UnmanagedPSEntry.Start(String[] args, Int32 argc) in /PowerShell/src/Microsoft.PowerShell.ConsoleHost/host/msh/ManagedEntrance.cs:line 99
```

This exception is thrown from Mutex ctor and isn't properly handled. This change fixes it.
@gukoff gukoff force-pushed the dont-crash-on-full-disk branch from 0a84be7 to a1f5b0a Compare June 14, 2021 10:59
@iSazonov iSazonov requested a review from JamesWTruher June 14, 2021 11:22
@rjmholt rjmholt requested a review from daxian-dbw June 14, 2021 17:32
Copy link
Member
@daxian-dbw daxian-dbw left a comment

Choose a reason f 8000 or hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rjmholt rjmholt merged commit da578e5 into PowerShell:master Jun 14, 2021
@rjmholt rjmholt added the CL-Engine Indicates that a PR should be marked as an engine change in the Change Log label Jun 16, 2021
@ghost
Copy link
ghost commented Jun 17, 2021

🎉v7.2.0-preview.7 has been released which incorporates this pull request.:tada:

Handy links:

@ghost
Copy link
ghost commented Oct 14, 2021

🎉v7.0.8 has been released which incorporates this pull request.:tada:

Handy links:

@ghost
Copy link
ghost commented Oct 14, 2021

🎉v7.1.5 has been released which incorporates this pull request.:tada:

Handy links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backport-7.0.x-Done BackPort-7.1.x-Done Backport to 7.1.x completed CL-Engine Indicates that a PR should be marked as an engine change in the Change Log
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0