Skip to content

Commit 4716346

Browse files
committed
Merge pull request #109 from qq254963746/develop
FIX 文件句柄 BUG
2 parents 00c58e8 + 446231d commit 4716346

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

lts-core/src/main/java/com/lts/core/commons/file/FileLock.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public FileLock(File file) {
3636
* 获得锁
3737
*/
3838
public boolean tryLock() {
39+
boolean success = false;
3940
try {
4041
Path path = Paths.get(file.getPath());
4142
if (channel != null && channel.isOpen()) {
@@ -44,17 +45,20 @@ public boolean tryLock() {
4445
channel = FileChannel.open(path, StandardOpenOption.WRITE, StandardOpenOption.READ);
4546
lock = channel.tryLock();
4647
if (lock != null) {
48+
success = true;
4749
return true;
4850
}
49-
} catch (IOException e) {
50-
if (channel != null) {
51-
try {
52-
channel.close();
53-
} catch (IOException e1) {
54-
LOGGER.error("file channel close failed.", e1);
51+
} catch (Exception e) {
52+
return false;
53+
} finally {
54+
if (!success) {
55+
if (channel != null) {
56+
try {
57+
channel.close();
58+
} catch (IOException ignored) {
59+
}
5560
}
5661
}
57-
return false;
5862
}
5963
return false;
6064
}

lts-core/src/main/java/com/lts/core/failstore/AbstractFailStore.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public List<FailStore> getDeadFailStores() {
6262
}
6363
} catch (Exception e) {
6464
// ignore
65+
LOGGER.error(e.getMessage(), e);
6566
}
6667
}
6768
}

lts-core/src/main/java/com/lts/core/support/RetryScheduler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,12 @@ public void run() {
243243
LOGGER.info("{} RetryScheduler, dead local files send success, size: {}, {}", name, values.size(), JSONUtils.toJSONString(values));
244244
store.delete(keys);
245245
} else {
246+
store.close();
246247
break;
247248
}
248249
try {
249250
Thread.sleep(500);
250-
} catch (Exception e) {
251+
} catch (Exception ignored) {
251252
}
252253
}
253254
}

0 commit comments

Comments
 (0)