Skip to content

Commit 289320f

Browse files
committed
git: consistently read from stdout before exit wait
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.
1 parent cf4b3e9 commit 289320f

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)