From 8e90acd333c19baaf1e98a56aa85f6b5d49e536a Mon Sep 17 00:00:00 2001 From: ivan-danilov Date: Sat, 17 Dec 2011 18:52:34 +0200 Subject: [PATCH] Added closing of stdout for child processes preventing the hang in some cases (fixes #121). Also removed close in another place as it is redundant now. --- GitTfs/Core/GitHelpers.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/GitTfs/Core/GitHelpers.cs b/GitTfs/Core/GitHelpers.cs index 0cff0e40..5d72704d 100644 --- a/GitTfs/Core/GitHelpers.cs +++ b/GitTfs/Core/GitHelpers.cs @@ -83,7 +83,6 @@ namespace Sep.Git.Tfs.Core public override void Close() { - process.StandardOutput.Close(); helper.Close(process); } @@ -191,6 +190,14 @@ namespace Sep.Git.Tfs.Core private void Close(Process process) { + // if caller doesn't read entire stdout to the EOF - it is possible that + // child process will hang waiting until there will be free space in stdout + // buffer to write the rest of the output. To prevent such situation we'll + // close stdout to indicate we're no more interested in it, thus allowing + // child process to proceed. + // See https://github.com/git-tfs/git-tfs/issues/121 for details. + process.StandardOutput.Close(); + if (!process.WaitForExit((int)TimeSpan.FromSeconds(10).TotalMilliseconds)) throw new GitCommandException("Command did not terminate.", process); if(process.ExitCode != 0)