You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@geode.apache.org by GitBox <gi...@apache.org> on 2022/04/12 21:36:15 UTC

[GitHub] [geode] kirklund commented on a diff in pull request #7582: GEODE-10184: Open status file for reading before handling request to avoid race conditions when accessing the file

kirklund commented on code in PR #7582:
URL: https://github.com/apache/geode/pull/7582#discussion_r848889861


##########
geode-core/src/main/java/org/apache/geode/internal/process/ControlFileWatchdog.java:
##########
@@ -73,12 +75,17 @@ public void run() {
   private void doWork() {
     try { // handle handle exceptions
       if (file.exists()) {
-        try { // always check stopAfterRequest after handleRequest
-          handleRequest();
-        } finally {
-          if (stopAfterRequest) {
-            stopMe();
+        // see if file is accessible
+        try (FileReader fileReader = new FileReader(file)) {
+          try { // always check stopAfterRequest after handleRequest
+            handleRequest(fileReader);
+          } finally {
+            if (stopAfterRequest) {
+              stopMe();
+            }
           }
+        } catch (FileNotFoundException e) {
+          e.printStackTrace();

Review Comment:
   We shouldn't use `printStackTrace`. You should use logger to log it at debug or warn or something like that.



##########
geode-core/src/main/java/org/apache/geode/internal/process/ControlFileWatchdog.java:
##########
@@ -93,12 +100,15 @@ private void doWork() {
     }
   }
 
-  private void handleRequest() throws IOException {
-    try { // always delete file after invoking handler
-      requestHandler.handleRequest();
+  private void handleRequest(FileReader fileReader) throws IOException {
+    // always delete file after invoking handler
+    try (FileReader reader = fileReader) {
+      requestHandler.handleRequest(reader);
     } finally {
       try {
-        file.delete();
+        if (!file.delete()) {
+          logger.warn("Unable to delete{}", file);

Review Comment:
   Need a space in `delete{}`



-- 
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: notifications-unsubscribe@geode.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org