From feefcb02b0215b6dea9be5efbb9a3f4048d8c0ff Mon Sep 17 00:00:00 2001 From: Zhen Chen Date: Mon, 31 Oct 2016 14:27:36 -0700 Subject: [PATCH] Fix flush call race condition in StreamCopyThread If there was a new flush() call during flush previous bytes, we need to catch it in order to process the new bytes between the two flush() calls instead of going to last catch IOException clause and end the thread. Change-Id: Ibc58a1fa97559238c13590aedbb85e482d85e465 Signed-off-by: Zhen Chen --- .../src/org/eclipse/jgit/util/io/StreamCopyThread.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/StreamCopyThread.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/StreamCopyThread.java index 8d39a22ac..eabe72b25 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/StreamCopyThread.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/StreamCopyThread.java @@ -118,7 +118,13 @@ public void run() { for (;;) { try { if (readInterrupted) { - dst.flush(); + try { + dst.flush(); + } catch (InterruptedIOException e) { + // There was a new flush() call during flush previous bytes + // need continue read/write/flush for the new bytes + continue; + } readInterrupted = false; if (!flushCount.compareAndSet(flushCountBeforeRead, 0)) { // There was a flush() call since last blocked read.