-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Fix CoreclrTestWrapperLib to be robust against exited processes #113937
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -111,6 +111,36 @@ public static unsafe bool ListChildPids(int ppid, out int[] buffer) | |
|
|
||
| internal static class ProcessExtensions | ||
| { | ||
| public static bool TryGetProcessId(this Process process, out int processId) | ||
| { | ||
| try | ||
| { | ||
| processId = process.Id; | ||
| return true; | ||
| } | ||
| catch | ||
| { | ||
| // Process exited | ||
| processId = default; | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| public static bool TryGetProcessName(this Process process, out string processName) | ||
| { | ||
| try | ||
| { | ||
| processName = process.ProcessName; | ||
| return true; | ||
| } | ||
| catch | ||
| { | ||
| // Process exited | ||
| processName = default; | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| public unsafe static IEnumerable<Process> GetChildren(this Process process) | ||
| { | ||
| var children = new List<Process>(); | ||
|
|
@@ -353,7 +383,7 @@ static bool RunProcess(string fileName, string arguments, TextWriter outputWrite | |
|
|
||
| Task<string> stdOut = proc.StandardOutput.ReadToEndAsync(); | ||
| Task<string> stdErr = proc.StandardError.ReadToEndAsync(); | ||
| if(!proc.WaitForExit(DEFAULT_TIMEOUT_MS)) | ||
| if (!proc.WaitForExit(DEFAULT_TIMEOUT_MS)) | ||
| { | ||
| proc.Kill(true); | ||
| outputWriter.WriteLine($"Timedout: '{fileName} {arguments}"); | ||
|
|
@@ -394,7 +424,7 @@ public static bool TryPrintStackTraceFromCrashReport(string crashReportJsonFile, | |
| string? userName = Environment.GetEnvironmentVariable("USER"); | ||
| if (string.IsNullOrEmpty(userName)) | ||
| { | ||
| userName="helixbot"; | ||
| userName = "helixbot"; | ||
| } | ||
|
|
||
| if (!RunProcess("sudo", $"chmod a+rw {crashReportJsonFile}", Console.Out)) | ||
|
|
@@ -569,7 +599,9 @@ public static bool TryPrintStackTraceFromCrashReport(string crashReportJsonFile, | |
|
|
||
| symbolizerOutput = stdout.Result; | ||
|
|
||
| } catch (Exception e) { | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| outputWriter.WriteLine("Errors while running llvm-symbolizer --pretty-print"); | ||
| outputWriter.WriteLine(e.ToString()); | ||
| return false; | ||
|
|
@@ -662,16 +694,23 @@ static unsafe IEnumerable<Process> FindChildProcessesByName(Process process, str | |
| while (childrenToCheck.Count != 0) | ||
| { | ||
| Process child = childrenToCheck.Dequeue(); | ||
| if (seen.Contains(child.Id)) | ||
|
|
||
| if (!child.TryGetProcessId(out int processId)) | ||
|
||
| continue; | ||
|
|
||
| if (seen.Contains(processId)) | ||
| continue; | ||
|
|
||
| Console.WriteLine($"Checking child process: '{child.ProcessName}' (ID: {child.Id})"); | ||
| seen.Add(child.Id); | ||
| if (!child.TryGetProcessName(out string processName)) | ||
| continue; | ||
|
|
||
| Console.WriteLine($"Checking child process: '{processName}' (ID: {processId})"); | ||
| seen.Add(processId); | ||
|
|
||
| foreach (var grandchild in child.GetChildren()) | ||
| childrenToCheck.Enqueue(grandchild); | ||
|
|
||
| if (child.ProcessName.Equals(childName, StringComparison.OrdinalIgnoreCase)) | ||
| if (processName.Equals(childName, StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| children.Push(child); | ||
| } | ||
|
|
@@ -789,7 +828,7 @@ public int RunTest(string executable, string outputFile, string errorFile, strin | |
| { | ||
| cts.Cancel(); | ||
| } | ||
| catch {} | ||
| catch { } | ||
|
|
||
| outputWriter.WriteLine("\ncmdLine:{0} Timed Out (timeout in milliseconds: {1}{2}{3}, start: {4}, end: {5})", | ||
| executable, timeout, (environmentVar != null) ? " from variable " : "", (environmentVar != null) ? TIMEOUT_ENVIRONMENT_VAR : "", | ||
|
|
@@ -851,7 +890,7 @@ private static string GetAllProcessNames_wmic() | |
| { | ||
| // The command to execute | ||
| string command = "wmic process get Name, ProcessId, ParentProcessId"; | ||
|
|
||
| // Start the process and capture the output | ||
| Process process = new Process(); | ||
| process.StartInfo.FileName = "cmd.exe"; | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The modified exception handling in the symbolizer output code introduces an additional catch block. Consider consolidating the error handling to streamline the code and ensure that no redundant catch blocks exist.