diff --git a/cadc-util/build.gradle b/cadc-util/build.gradle index c79d4361..89d18599 100644 --- a/cadc-util/build.gradle +++ b/cadc-util/build.gradle @@ -16,7 +16,7 @@ sourceCompatibility = 1.8 group = 'org.opencadc' -version = '1.5.9' +version = '1.5.10' description = 'OpenCADC core utility library' def git_url = 'https://github.com/opencadc/core' diff --git a/cadc-util/src/main/java/ca/nrc/cadc/io/MultiBufferIO.java b/cadc-util/src/main/java/ca/nrc/cadc/io/MultiBufferIO.java index 5388eebd..930be3c2 100644 --- a/cadc-util/src/main/java/ca/nrc/cadc/io/MultiBufferIO.java +++ b/cadc-util/src/main/java/ca/nrc/cadc/io/MultiBufferIO.java @@ -67,7 +67,6 @@ package ca.nrc.cadc.io; -import ca.nrc.cadc.thread.ConditionVar; import java.io.InputStream; import java.io.OutputStream; import java.util.concurrent.BlockingQueue; @@ -131,22 +130,36 @@ public void copy(InputStream input, OutputStream output) throws InterruptedExcep } Worker w = new Worker(output); - Thread writer = new Thread(w); - writer.start(); - - Throwable readFail = doit(input, w); - log.debug("reader completed: " + readFail); - if (readFail != null) { - writer.interrupt(); - } - writer.join(); - log.debug("writer completed: " + w.fail); - - if (readFail != null) { - throw new ReadException(READ_FAIL, readFail); - } - if (w.fail != null) { - throw new WriteException(WRITE_FAIL, w.fail); + Thread writer = new Thread(w, MultiBufferIO.class.getSimpleName() + "-writer"); + try { + writer.start(); + + Throwable readFail = doit(input, w); + log.debug("reader completed: " + readFail); + if (readFail != null) { + writer.interrupt(); + } + writer.join(); + log.debug("writer completed: " + w.fail); + + if (readFail != null) { + throw new ReadException(READ_FAIL, readFail); + } + if (w.fail != null) { + throw new WriteException(WRITE_FAIL, w.fail); + } + } finally { + if (writer.isAlive()) { + try { + log.error("BUG: " + writer.getName() + " still alive in finally - interrupting..."); + writer.interrupt(); + log.error("BUG: " + writer.getName() + " interrupted in finally - waiting..."); + writer.join(); + log.error("BUG: " + writer.getName() + " still alive in finally - finished"); + } catch (Exception ex) { + log.error("OOPS: failed to kill " + writer.getName(), ex); + } + } } }