Add some safety to closing the writer and deleting the lock file

Fixes #7822
This commit is contained in:
Rob Bavey 2017-07-26 15:49:50 -04:00
parent 435466b6b0
commit 669be49408

View file

@ -146,17 +146,33 @@ public final class DeadLetterQueueWriter implements Closeable {
@Override @Override
public synchronized void close() throws IOException { public synchronized void close() throws IOException {
if (this.lock != null){ if (currentWriter != null) {
this.lock.release(); try {
if (this.lock.channel() != null && this.lock.channel().isOpen()) { currentWriter.close();
this.lock.channel().close(); open = false;
}catch (Exception e){
logger.debug("Unable to close dlq writer", e);
} }
} }
if (currentWriter != null) { releaseLock();
currentWriter.close(); }
private void releaseLock() {
if (this.lock != null){
try {
this.lock.release();
if (this.lock.channel() != null && this.lock.channel().isOpen()) {
this.lock.channel().close();
}
} catch (Exception e) {
logger.debug("Unable to close lock channel", e);
}
try {
Files.deleteIfExists(queuePath.resolve(LOCK_FILE));
} catch (IOException e){
logger.debug("Unable to delete lock file", e);
}
} }
Files.deleteIfExists(queuePath.resolve(LOCK_FILE));
open = false;
} }
public boolean isOpen() { public boolean isOpen() {