Skip to content
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
SuggestionStore::GetCompletions to check exit code of invoked applica…
…tion

Fix #2147
  • Loading branch information
baradgur committed Apr 11, 2023
commit d3e8b473c1c92f83386f61c3a4fb2e53211f8b26
2 changes: 1 addition & 1 deletion src/System.CommandLine.Suggest/SuggestionStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public string GetCompletions(string exeFileName, string suggestionTargetArgument

Task<string> readToEndTask = process.StandardOutput.ReadToEndAsync();

if (readToEndTask.Wait(timeout))
if (readToEndTask.Wait(timeout) && process.HasExited && process.ExitCode == 0)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The else block might need some additional checks as well. It doesn't appear that we have code coverage over both of these code branches.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is entirely reliable. If the child process first closes its standard output and then exits, then readToEndTask.Wait might complete while process.HasExited is still false. And maybe that can even happen if the child process does not intentionally delay exiting. It might be more reliable to also call Process.WaitForExit(TimeSpan) with a small grace period.

{
result = readToEndTask.Result;
}
Expand Down