diff --git a/Bonobo.Git.Server/Git/GitService/GitServiceExecutor.cs b/Bonobo.Git.Server/Git/GitService/GitServiceExecutor.cs index 746a2acf7..57b8b3683 100644 --- a/Bonobo.Git.Server/Git/GitService/GitServiceExecutor.cs +++ b/Bonobo.Git.Server/Git/GitService/GitServiceExecutor.cs @@ -5,8 +5,8 @@ using System.Web.Mvc; using System.Linq; using System; -using System.Collections.Generic; using System.Diagnostics; +using System.Threading; namespace Bonobo.Git.Server.Git.GitService { @@ -37,6 +37,12 @@ public GitServiceExecutor(GitServiceExecutorParams parameters, IGitRepositoryLoc this.repoLocator = repoLocator; } + private class StreamHelper + { + public Stream FromStream { get; set; } + public Stream ToStream { get; set; } + } + public void ExecuteServiceByName( string correlationId, string repositoryName, @@ -93,18 +99,41 @@ public void ExecuteServiceByName( using (var process = Process.Start(info)) { - inStream.CopyTo(process.StandardInput.BaseStream); - if (options.endStreamWithClose) { - process.StandardInput.Close(); - } else { - process.StandardInput.Write('\0'); - } - - process.StandardOutput.BaseStream.CopyTo(outStream); - process.WaitForExit(); + var readStreamHelper = new StreamHelper { + FromStream = process.StandardOutput.BaseStream, + ToStream = outStream + }; + + //Seperate thread for reading the output to prevent a buffer overflow at the 4k console buffer limit + var thrdRead = new Thread((obj) => { + try + { + var strmHelper = (StreamHelper) obj; + strmHelper.FromStream.CopyTo(strmHelper.ToStream); + } + //Extra to prevent error if client disconnected + catch (System.Web.HttpException) + { + } + }); + + thrdRead.Start(readStreamHelper); + + inStream.CopyTo(process.StandardInput.BaseStream); + if (options.endStreamWithClose) { + process.StandardInput.Close(); + } else { + process.StandardInput.Write('\0'); + } + + process.WaitForExit(); + + thrdRead.Abort(); + } } + private void SetHomePath(ProcessStartInfo info) { if (info.EnvironmentVariables.ContainsKey("HOME"))