Jackeyzhe commented on code in PR #3368:
URL: https://github.com/apache/fluss/pull/3368#discussion_r3407838361
##########
fluss-common/src/main/java/org/apache/fluss/utils/FileLock.java:
##########
@@ -106,21 +122,42 @@ public void unlock() throws IOException {
*/
public void unlockAndDestroy() throws IOException {
try {
- unlock();
- if (lock != null) {
- lock.channel().close();
- lock = null;
- }
- if (outputStream != null) {
- outputStream.close();
- outputStream = null;
+ try {
+ unlock();
+ } finally {
+ try {
+ if (lock != null) {
+ lock.channel().close();
+ lock = null;
+ }
+ } finally {
+ // Always close the output stream, even when releasing or
closing the channel
+ // above threw; otherwise the file descriptor would leak
whenever cleanup
+ // failed partway through.
+ if (outputStream != null) {
+ outputStream.close();
+ outputStream = null;
+ }
+ }
}
-
} finally {
this.file.delete();
}
}
+ private void closeOutputStreamQuietly() {
+ if (outputStream == null) {
+ return;
+ }
+ try {
+ outputStream.close();
+ } catch (IOException ignored) {
+ // Best-effort cleanup; the original failure will be propagated by
the caller.
Review Comment:
nit: Maybe we should add a log here ensure user know the outputStream close
fail
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]