@@ -5,6 +5,7 @@ namespace VirtualClient.Actions
55{
66 using System ;
77 using System . Collections . Generic ;
8+ using System . Diagnostics ;
89 using System . IO ;
910 using System . IO . Abstractions ;
1011 using System . Linq ;
@@ -161,22 +162,20 @@ protected override async Task InitializeAsync(EventContext telemetryContext, Can
161162 {
162163 using ( IProcessProxy process = this . processManager . CreateProcess ( this . ExecutablePath , $ "--unlock { email } { licenseKey } ") )
163164 {
164- this . CleanupTasks . Add ( ( ) =>
165+ try
165166 {
166- // Note:
167- // Issues were found on Linux/ARM64 systems with the process failing to be killed
168- // using standard .NET logic. This happens on Ampere systems with lots of cores.
169- // We are using the 'kill -9' option as a workaround.
170- this . processManager . SafeKill ( process , this . Logger ) ;
171- } ) ;
167+ await process . StartAndWaitAsync ( cancellationToken , withExitConfirmation : true ) ;
172168
173- await process . StartAndWaitAsync ( cancellationToken ) ;
174-
175- if ( ! cancellationToken . IsCancellationRequested )
169+ if ( ! cancellationToken . IsCancellationRequested )
170+ {
171+ await this . LogProcessDetailsAsync ( process , telemetryContext , this . PackageName ) ;
172+ process . ThrowIfDependencyInstallationFailed ( ) ;
173+ }
174+ }
175+ finally
176176 {
177- await this . LogProcessDetailsAsync ( process , telemetryContext , this . PackageName , logToFile : true ) ;
178-
179- process . ThrowIfDependencyInstallationFailed ( ) ;
177+ process . Close ( ) ;
178+ process . SafeKill ( this . Logger , TimeSpan . FromSeconds ( 30 ) ) ;
180179 }
181180 }
182181 }
@@ -213,6 +212,7 @@ private void CaptureMetrics(IProcessProxy process, string standardOutput, string
213212 // using workload name as testName
214213 GeekBenchMetricsParser geekbenchMetricsParser = new GeekBenchMetricsParser ( standardOutput ) ;
215214 IList < Metric > metrics = geekbenchMetricsParser . Parse ( ) ;
215+
216216 foreach ( Metric metric in metrics )
217217 {
218218 this . Logger . LogMetric (
@@ -259,24 +259,23 @@ private Task ExecuteWorkloadAsync(string pathToExe, string commandLineArguments,
259259 {
260260 using ( IProcessProxy process = this . processManager . CreateProcess ( pathToExe , commandLineArguments ) )
261261 {
262- this . CleanupTasks . Add ( ( ) =>
262+ try
263263 {
264- // Note:
265- // Issues were found on Linux/ARM64 systems with the process failing to be killed
266- // using standard .NET logic. This happens on Ampere systems with lots of cores.
267- // We are using the 'kill -9' option as a workaround.
268- this . processManager . SafeKill ( process , this . Logger ) ;
269- } ) ;
264+ await process . StartAndWaitAsync ( cancellationToken , withExitConfirmation : true ) ;
270265
271- await process . StartAndWaitAsync ( cancellationToken ) ;
266+ if ( ! cancellationToken . IsCancellationRequested )
267+ {
268+ await this . LogProcessDetailsAsync ( process , telemetryContext , this . PackageName ) ;
269+ process . ThrowIfWorkloadFailed ( ) ;
272270
273- if ( ! cancellationToken . IsCancellationRequested )
271+ string standardOutput = process . StandardOutput . ToString ( ) ;
272+ this . CaptureMetrics ( process , standardOutput , commandLineArguments , telemetryContext , cancellationToken ) ;
273+ }
274+ }
275+ finally
274276 {
275- await this . LogProcessDetailsAsync ( process , telemetryContext , this . PackageName , logToFile : true ) ;
276- process . ThrowIfWorkloadFailed ( ) ;
277-
278- string standardOutput = process . StandardOutput . ToString ( ) ;
279- this . CaptureMetrics ( process , standardOutput , commandLineArguments , telemetryContext , cancellationToken ) ;
277+ process . Close ( ) ;
278+ process . SafeKill ( this . Logger , TimeSpan . FromSeconds ( 30 ) ) ;
280279 }
281280 }
282281 }
0 commit comments