From e4d2f1ab68832df120b137ac722be8b27eca55df Mon Sep 17 00:00:00 2001 From: Kris Borowinski Date: Sat, 18 May 2024 16:20:58 +0200 Subject: [PATCH] Add null check for $host.UI and its properties to avoid race condition (#2383) --- src/functions/Output.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/functions/Output.ps1 b/src/functions/Output.ps1 index d9df42923..c376e97c6 100644 --- a/src/functions/Output.ps1 +++ b/src/functions/Output.ps1 @@ -1127,7 +1127,8 @@ function Resolve-OutputConfiguration ([PesterConfiguration]$PesterPreference) { # https://no-color.org/) $PesterPreference.Output.RenderMode = 'Plaintext' } - elseif (($supportsVT = $host.UI.psobject.Properties['SupportsVirtualTerminal']) -and $supportsVT.Value) { + # Null check $host.UI and its properties to avoid race condition when accessing them from multiple threads. https://github.com/pester/Pester/issues/2383 + elseif ($null -ne $host.UI -and ($hostProperties = $host.UI.psobject.Properties) -and ($supportsVT = $hostProperties['SupportsVirtualTerminal']) -and $supportsVT.Value) { $PesterPreference.Output.RenderMode = 'Ansi' } else {