summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Ostrovsky <david@ostrovsky.org>2018-09-15 21:09:51 +0200
committerDavid Ostrovsky <d.ostrovsky@gmx.de>2018-09-17 06:46:16 -0500
commit5c134f4d42e12e9192f2beca8370c1b8bd58c08d (patch)
tree2deefef5d041bcc76c2acb086a3c051c314d8d56
parentf8e514c74a039209488ef56948c784c00a1d87b3 (diff)
downloadjgit-5c134f4d42e12e9192f2beca8370c1b8bd58c08d.tar.gz
jgit-5c134f4d42e12e9192f2beca8370c1b8bd58c08d.zip
ObjectDownloadListener#onWritePossible: Make code spec compatible
Current code violates the ServletOutputStream contract. For every out.isReady() == true either write or close of that ServletOutputStream should be called. See also this issue upstream for more context: [1]. [1] https://github.com/eclipse/jetty.project/issues/2911 Change-Id: Ied575f3603a6be0d2dafc6c3329d685fc212c7a3 Signed-off-by: David Ostrovsky <david@ostrovsky.org> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
-rw-r--r--org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/ObjectDownloadListener.java32
1 files changed, 19 insertions, 13 deletions
diff --git a/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/ObjectDownloadListener.java b/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/ObjectDownloadListener.java
index 0b96426420..60258602f1 100644
--- a/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/ObjectDownloadListener.java
+++ b/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/ObjectDownloadListener.java
@@ -80,7 +80,7 @@ public class ObjectDownloadListener implements WriteListener {
private final WritableByteChannel outChannel;
- private final ByteBuffer buffer = ByteBuffer.allocateDirect(8192);
+ private ByteBuffer buffer = ByteBuffer.allocateDirect(8192);
/**
* @param repository
@@ -115,20 +115,26 @@ public class ObjectDownloadListener implements WriteListener {
@Override
public void onWritePossible() throws IOException {
while (out.isReady()) {
- if (in.read(buffer) != -1) {
- buffer.flip();
- outChannel.write(buffer);
- buffer.compact();
- } else {
- in.close();
- buffer.flip();
- while (out.isReady()) {
- if (buffer.hasRemaining()) {
- outChannel.write(buffer);
- } else {
+ try {
+ buffer.clear();
+ if (in.read(buffer) < 0) {
+ buffer = null;
+ } else {
+ buffer.flip();
+ }
+ } catch(Throwable t) {
+ LOG.log(Level.SEVERE, t.getMessage(), t);
+ buffer = null;
+ } finally {
+ if (buffer != null) {
+ outChannel.write(buffer);
+ } else {
+ try {
+ out.close();
+ } finally {
context.complete();
- return;
}
+ return;
}
}
}