mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 22:57:16 -04:00
Add some safety to closing the writer and deleting the lock file
Fixes #7822
This commit is contained in:
parent
435466b6b0
commit
669be49408
1 changed files with 24 additions and 8 deletions
|
@ -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() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue