Repository navigation
Fix certificate manager process deadlocks in .NET 10 #69051
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
24a3e58
147f034
b4b8a02
a821004
8294219
34d3e67
946305c
3a829bc
a5d4ea8
1e9f487
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| #nullable enable | ||
|
|
||
| using System.Diagnostics; | ||
| using System.Text; | ||
|
|
||
| namespace Microsoft.AspNetCore.Certificates.Generation; | ||
|
|
||
| internal static class CertificateManagerProcessRunner | ||
| { | ||
| internal static ProcessExecutionResult Run(ProcessStartInfo processInfo) | ||
|
adamsitnik marked this conversation as resolved.
Resolved
|
||
| { | ||
| using var process = Process.Start(processInfo) | ||
| ?? throw new InvalidOperationException($"Failed to start process '{processInfo.FileName}'."); | ||
|
Youssef1313 marked this conversation as resolved.
Resolved
|
||
|
|
||
| StringBuilder? outBuilder = null; | ||
| StringBuilder? errBuilder = null; | ||
| if (processInfo.RedirectStandardOutput) | ||
| { | ||
| process.OutputDataReceived += (_, e) => | ||
| { | ||
| if (e.Data is not null) | ||
| { | ||
| (outBuilder ??= new()).AppendLine(e.Data); | ||
| } | ||
| }; | ||
|
|
||
| process.BeginOutputReadLine(); | ||
| } | ||
|
Youssef1313 marked this conversation as resolved.
Resolved
|
||
|
|
||
| if (processInfo.RedirectStandardError) | ||
| { | ||
| process.ErrorDataReceived += (_, e) => | ||
| { | ||
| if (e.Data is not null) | ||
| { | ||
| (errBuilder ??= new()).AppendLine(e.Data); | ||
| } | ||
| }; | ||
|
|
||
| process.BeginErrorReadLine(); | ||
| } | ||
|
|
||
| process.WaitForExit(); | ||
|
|
||
| return new ProcessExecutionResult(process.ExitCode, outBuilder?.ToString() ?? string.Empty, errBuilder?.ToString() ?? string.Empty); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: we could delay the allocation of both strings to the moment where the properties are being requested for the first time, so in case Since this is just a backport and the previous version was already allocating this memory, it's just something to consider, not a must have |
||
| } | ||
|
|
||
| internal static int RunAndDiscardOutput(ProcessStartInfo processInfo) | ||
| { | ||
| using var process = Process.Start(processInfo) | ||
| ?? throw new InvalidOperationException($"Failed to start process '{processInfo.FileName}'."); | ||
|
|
||
| if (processInfo.RedirectStandardOutput) | ||
| { | ||
| process.OutputDataReceived += static (_, _) => { }; | ||
| process.BeginOutputReadLine(); | ||
| } | ||
|
|
||
| if (processInfo.RedirectStandardError) | ||
| { | ||
| process.ErrorDataReceived += static (_, _) => { }; | ||
| process.BeginErrorReadLine(); | ||
| } | ||
|
|
||
| process.WaitForExit(); | ||
| return process.ExitCode; | ||
| } | ||
| } | ||
|
|
||
| internal readonly record struct ProcessExecutionResult(int ExitCode, string StandardOutput, string StandardError); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
subjective nit: this class could be just called
ProcessRunneras its more or less general purpose utilityThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes sense, but as we are unlikely to repurpose this helper for anything else in release/10.0, I'll keep the existing name to get this in faster (but I admit that I agree ProcessRunner is a better name)