mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 14:47:19 -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
|
||||
public synchronized void close() throws IOException {
|
||||
if (this.lock != null){
|
||||
this.lock.release();
|
||||
if (this.lock.channel() != null && this.lock.channel().isOpen()) {
|
||||
this.lock.channel().close();
|
||||
if (currentWriter != null) {
|
||||
try {
|
||||
currentWriter.close();
|
||||
open = false;
|
||||
}catch (Exception e){
|
||||
logger.debug("Unable to close dlq writer", e);
|
||||
}
|
||||
}
|
||||
if (currentWriter != null) {
|
||||
currentWriter.close();
|
||||
releaseLock();
|
||||
}
|
||||
|
||||
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() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue