UploadPack: Don't buffer ls-refs output

Once we have read the user's entire command, there is no more need to
buffer our response --- even the strictest servlet engine allows
writing output once the input has been consumed.  Noticed when the
analogous code in the "fetch" command (introduced in a later patch)
overflowed its buffer:

 java.lang.OutOfMemoryError
        at java.io.ByteArrayOutputStream.hugeCapacity(ByteArrayOutputStream.java:123)
 [...]
        at org.eclipse.jgit.transport.UploadPack.sendPack(UploadPack.java:1905)
        at org.eclipse.jgit.transport.UploadPack.sendPack(UploadPack.java:1741)
        at org.eclipse.jgit.transport.UploadPack.fetchV2(UploadPack.java:1001)
        at org.eclipse.jgit.transport.UploadPack.serviceV2(UploadPack.java:1030)
        at org.eclipse.jgit.transport.UploadPack.upload(UploadPack.java:726)
        at org.eclipse.jgit.http.server.UploadPackServlet.doPost(UploadPackServlet.java:195)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)

Change-Id: I33df56f1cb1c6c2c25ee95426cb7ad665134ac6b
This commit is contained in:
Jonathan Nieder 2018-04-20 16:34:15 -07:00
parent 332bc61124
commit a99bbf162a
1 changed files with 1 additions and 0 deletions

View File

@ -890,6 +890,7 @@ private void lsRefsV2() throws IOException {
} else if (line != PacketLineIn.END) {
throw new PackProtocolException("unexpected " + line);
}
rawOut.stopBuffering();
adv.send(refs);
adv.end();