Skip to content

Commit 8b4735f

Browse files
authored
git: consistently read from stdout before exit wait (#1136)
We should always try and drain standard output before waiting for the Git process to exit. We do this for all other calls that expect output, but missed the `TryGet` method. This is important if Git ever writes out so much data to stdout that we buffer the output, and then Git will not exit until it can finish writing (and we'd be waiting for Git to exit).
2 parents b5e0201 + 289320f commit 8b4735f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/shared/Core/GitConfiguration.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ public bool TryGet(GitConfigurationLevel level, GitConfigurationType type, strin
199199
using (Process git = _git.CreateProcess($"config --null {levelArg} {typeArg} {QuoteCmdArg(name)}"))
200200
{
201201
git.Start();
202+
// To avoid deadlocks, always read the output stream first and then wait
203+
// TODO: don't read in all the data at once; stream it
204+
string data = git.StandardOutput.ReadToEnd();
202205
git.WaitForExit();
203206

204207
switch (git.ExitCode)
@@ -214,7 +217,6 @@ public bool TryGet(GitConfigurationLevel level, GitConfigurationType type, strin
214217
return false;
215218
}
216219

217-
string data = git.StandardOutput.ReadToEnd();
218220
string[] entries = data.Split('\0');
219221
if (entries.Length > 0)
220222
{
@@ -301,7 +303,7 @@ public IEnumerable<string> GetAll(GitConfigurationLevel level, GitConfigurationT
301303
using (Process git = _git.CreateProcess(gitArgs))
302304
{
303305
git.Start();
304-
306+
// To avoid deadlocks, always read the output stream first and then wait
305307
// TODO: don't read in all the data at once; stream it
306308
string data = git.StandardOutput.ReadToEnd();
307309
git.WaitForExit();

0 commit comments

Comments
 (0)