()
| 374 | } |
| 375 | |
| 376 | private async ValueTask StopAsync() |
| 377 | { |
| 378 | if (!this.IsRunning) |
| 379 | { |
| 380 | return; |
| 381 | } |
| 382 | |
| 383 | var process = this.driverServiceProcess; |
| 384 | using var timeoutCts = new CancellationTokenSource(this.TerminationTimeout); |
| 385 | |
| 386 | try |
| 387 | { |
| 388 | // Send graceful shutdown signal |
| 389 | _ = SendShutdownSignalAsync(process, timeoutCts.Token); |
| 390 | |
| 391 | // Wait for process to exit |
| 392 | await WaitForProcessExitAsync(process, timeoutCts.Token).ConfigureAwait(false); |
| 393 | } |
| 394 | catch (OperationCanceledException) |
| 395 | { |
| 396 | // Timeout occurred, force kill |
| 397 | if (_logger.IsEnabled(LogEventLevel.Warn)) |
| 398 | { |
| 399 | _logger.Warn($"Driver service did not exit within {this.TerminationTimeout.TotalSeconds} seconds. Forcing termination."); |
| 400 | } |
| 401 | |
| 402 | TryKillProcess(process); |
| 403 | } |
| 404 | catch (InvalidOperationException) |
| 405 | { |
| 406 | // Process already exited or is in an invalid state, which is acceptable during shutdown |
| 407 | } |
| 408 | finally |
| 409 | { |
| 410 | process.Dispose(); |
| 411 | this.driverServiceProcess = null; |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | private static async Task WaitForProcessExitAsync(Process process, CancellationToken cancellationToken) |
| 416 | { |
no test coverage detected