Skip to content

SuggestionStore::GetCompletions to check exit code of invoked applica… #2160

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

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
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
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
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.

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