Copilot commented on code in PR #3368:
URL: https://github.com/apache/fluss/pull/3368#discussion_r3410681430


##########
fluss-common/src/main/java/org/apache/fluss/utils/FileLock.java:
##########
@@ -106,21 +127,44 @@ public void unlock() throws IOException {
      */
     public void unlockAndDestroy() throws IOException {
         try {
-            unlock();
-            if (lock != null) {
-                lock.channel().close();
-                lock = 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;
+                    }

Review Comment:
   If `outputStream.close()` throws, `outputStream` is not set to null, which 
can leave the instance in a partially-destroyed state and interfere with later 
`tryLock()` re-initialization. Set `outputStream = null` in a `finally` to 
guarantee state reset even when close fails.



##########
fluss-common/src/main/java/org/apache/fluss/utils/FileLock.java:
##########
@@ -106,21 +127,44 @@ public void unlock() throws IOException {
      */
     public void unlockAndDestroy() throws IOException {
         try {
-            unlock();
-            if (lock != null) {
-                lock.channel().close();
-                lock = null;
+            try {
+                unlock();
+            } finally {
+                try {
+                    if (lock != null) {
+                        lock.channel().close();
+                        lock = null;
+                    }

Review Comment:
   If `lock.channel().close()` throws, `lock` remains non-null, leaving 
`FileLock` in an inconsistent state (and potentially preventing reuse/cleanup 
logic that relies on `lock == null`). Consider nulling `lock` in a `finally` so 
the internal state is reset even when close fails.



-- 
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]

Reply via email to