2

We're utilizing Bonobo Git Server to host some internal git repos. When attempting to check out one of our repositories we're getting this error returned:

RPC Failed; result=22, HTTP code = 500

fatal: The remote end hung up unexpectedly

In the Windows Event Viewer it logs this message:

Exception information: 
    Exception type: ArithmeticException 
    Exception message: Overflow or underflow in the arithmetic operation.
Request information: 
    Request URL: http://localhost:50287/MyRepo.git/git-upload-pack 
    Request path: /MyRepo.git/git-upload-pack 

If I debug Bonobo locally no exception is thrown in C#; it comes from the outstream of the git process. The code utlizes Process to run git.exe like so:

using (var process = System.Diagnostics.Process.Start(info))
{
    inStream.CopyTo(process.StandardInput.BaseStream);
    process.StandardInput.Write('\0');
    process.StandardOutput.BaseStream.CopyTo(outStream);

    process.WaitForExit();
}

The command arguments passed to git are:

upload-pack --stateless-rpc D:\PathToRepos\MyRepo

If I run git.exe with the clone command from a command prompt, the project clones properly (with a warning of templates not found)

I'm thinking that it's a datatype issue between C# and what git is streaming to the Response.OutputStream.

Community
  • 1
  • 1
Dave Zych
  • 21,581
  • 7
  • 51
  • 66
  • Is it possible that the warning is somehow mis-interpreted as a non-vlid answer from the server by Bobobo? The only other similar case I found suggests a problem with the git install on the remote side (https://github.com/gitlabhq/gitlabhq/issues/3958#issuecomment-18077589). I suppose it isn't the case here, especially if "remote" is on localhost and other repos are cloning just fine? – VonC Jan 03 '14 at 06:00
  • @VonC I don't think the template error is the issue... if I locally clone a project that I'm able to remotely clone I still see the template error. I did realize, however, that a clone isn't the same thing as an upload-pack (right?) so it's not exactly a fair comparison. How can I test this? – Dave Zych Jan 03 '14 at 17:10
  • The link I mentioned wasn't about the template, but now that you mention it, double-check your Git installation (and the exact git used by the Bonobo process): maybe it isn't completely/correctly installed. – VonC Jan 03 '14 at 17:31
  • Now, the `upload-pack` is part of the clone process: https://github.com/git/git/blob/master/Documentation/technical/pack-protocol.txt, to send to the server what the client have, in order for the server to return only what is missing. Is it a memory issue on the Bonobo server side as in http://stackoverflow.com/a/9469744/6309? – VonC Jan 03 '14 at 17:35
  • @VonC interesting... It definitely could be a memory issue. I'll review the SO answer you linked, implement it and see. Thanks! – Dave Zych Jan 03 '14 at 17:49
  • @VonC thanks for your help! I figured out that the response was being buffered which caused the exception. Setting `Response.Buffer = false` fixed it. – Dave Zych Jan 17 '14 at 21:58

1 Answers1

2

The issue was due to the response buffering the output. It would attempt to buffer the entire stream in memory prior to sending it and with large repositories this caused the ArithmeticException. Since Response.Buffer defaults to true, it must explicitly be set to false prior to sending the data. The data also has to obviously be read and streamed in chunks.

Response.Buffer = false;

while ((read = process.StandardOutput.BaseStream.Read(buffer, 0, buffer.Length)) > 0)
{
    Response.OutputStream.Write(buffer, 0, read);
    Response.OutputStream.Flush();
}
Dave Zych
  • 21,581
  • 7
  • 51
  • 66