From da578e5f341e257375dd163bed05bf69a9444b89 Mon Sep 17 00:00:00 2001 From: Konstantin Gukov Date: Mon, 14 Jun 2021 20:59:20 +0200 Subject: [PATCH] Do not stop powershell when can't create telemetry mutex. (#15574) --- .../utils/Telemetry.cs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/System.Management.Automation/utils/Telemetry.cs b/src/System.Management.Automation/utils/Telemetry.cs index 3ff3c90886..b00a472922 100644 --- a/src/System.Management.Automation/utils/Telemetry.cs +++ b/src/System.Management.Automation/utils/Telemetry.cs @@ -835,29 +835,30 @@ namespace Microsoft.PowerShell.Telemetry // 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;