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 <czhen@google.com>
This commit is contained in:
Zhen Chen 2016-10-31 14:27:36 -07:00
parent 83555e7e30
commit feefcb02b0
1 changed files with 7 additions and 1 deletions

View File

@ -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.