Browse Source

Fix stdout/stderr deadlock in CmdHelper.RunCmdAndGetOutput

Read stdout and stderr concurrently to prevent pipe buffer deadlock.
The sequential ReadToEnd() calls caused a hang when child processes
(e.g. dotnet build) produced enough stderr output to fill the OS
pipe buffer (~4KB on Windows), since the parent blocked on stdout
while the child blocked on stderr.

Made-with: Cursor
pull/25155/head
enisn 5 months ago
parent
commit
c1b1442d0f
No known key found for this signature in database GPG Key ID: A052619F04155D1C
  1. 18
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Utils/CmdHelper.cs

18
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Utils/CmdHelper.cs

@ -1,7 +1,8 @@
using System;
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using Volo.Abp.DependencyInjection;
@ -137,14 +138,13 @@ public class CmdHelper : ICmdHelper, ITransientDependency
process.Start();
using (var standardOutput = process.StandardOutput)
{
using (var standardError = process.StandardError)
{
output = standardOutput.ReadToEnd();
output += standardError.ReadToEnd();
}
}
var outputTask = process.StandardOutput.ReadToEndAsync();
var errorTask = process.StandardError.ReadToEndAsync();
output = Task.WhenAll(outputTask, errorTask).GetAwaiter().GetResult()
is { Length: 2 } results
? results[0] + results[1]
: string.Empty;
process.WaitForExit();

Loading…
Cancel
Save