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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
8000
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions src/System.Management.Automation/utils/Telemetry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -835,29 +835,30 @@ private static Guid GetUniqueIdentifier()

// Multiple processes may start simultaneously so we need a system wide
// way to control access to the file in the case (although remote) when we have
// simulataneous shell starts without the persisted file which attempt to create the file.
using (var m = new Mutex(true, "CreateUniqueUserId"))
// simultaneous shell starts without the persisted file which attempt to create the file.
try
{
// TryCreateUniqueIdentifierAndFile shouldn't throw, but the mutex might
using var m = new Mutex(true, "CreateUniqueUserId");
m.WaitOne();
try
{
m.WaitOne();
if (TryCreateUniqueIdentifierAndFile(uuidPath, out id))
{
return id;
}
}
catch (Exception)
{
// Any problem in generating a uuid will result in no telemetry being sent.
// Try to send the failure in telemetry, but it will have no unique id.
s_telemetryClient.GetMetric(_telemetryFailure, "Detail").TrackValue(1, "mutex");
}
finally
{
m.ReleaseMutex();
}
}
catch (Exception)
{
// Any problem in generating a uuid will result in no telemetry being sent.
// Try to send the failure in telemetry, but it will have no unique id.
s_telemetryClient.GetMetric(_telemetryFailure, "Detail").TrackValue(1, "mutex");
}

// something bad happened, turn off telemetry since the unique id wasn't set.
CanSendTelemetry = false;
Expand Down
0