{"record":{"id":"dd8ba2de1e2c4450","repo":"apache/hadoop","slug":"wait-interrupted","errorCode":null,"errorMessage":"Wait Interrupted","messagePattern":"Wait Interrupted","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java","lineNumber":738,"sourceCode":"      }\n    } else {\n      boolean inSafeMode = dfs.setSafeMode(action);\n      if (waitExitSafe) {\n        inSafeMode = waitExitSafeMode(dfs, inSafeMode);\n      }\n      System.out.println(\"Safe mode is \" + (inSafeMode ? \"ON\" : \"OFF\"));\n    }\n\n  }\n\n  @SuppressWarnings(\"deprecation\")\n  private boolean waitExitSafeMode(DistributedFileSystem dfs, boolean inSafeMode)\n      throws IOException {\n    while (inSafeMode) {\n      try {\n        Thread.sleep(5000);\n      } catch (java.lang.InterruptedException e) {\n        throw new IOException(\"Wait Interrupted\");\n      }\n      inSafeMode = dfs.setSafeMode(SafeModeAction.SAFEMODE_GET, false);\n    }\n    return inSafeMode;\n  }\n\n  private boolean waitExitSafeMode(ClientProtocol nn, boolean inSafeMode)\n      throws IOException {\n    while (inSafeMode) {\n      try {\n        Thread.sleep(5000);\n      } catch (java.lang.InterruptedException e) {\n        throw new IOException(\"Wait Interrupted\");\n      }\n      inSafeMode = nn.setSafeMode(SafeModeAction.SAFEMODE_GET, false);\n    }\n    return inSafeMode;\n  }","sourceCodeStart":720,"sourceCodeEnd":756,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java#L720-L756","documentation":"DFSAdmin.waitExitSafeMode(DistributedFileSystem, boolean) implements `hdfs dfsadmin -safemode wait`: it sleeps 5 seconds and re-queries setSafeMode(SAFEMODE_GET) until the NameNode leaves safe mode. If the calling thread is interrupted during Thread.sleep, the InterruptedException is swallowed and rethrown as IOException('Wait Interrupted'); the thread's interrupted flag is NOT restored, so interruption state is lost.","triggerScenarios":"Interrupting dfsadmin -safemode wait while the NN is still in safe mode: container SIGTERM with a grace period, orchestrator timeout killing the CLI, embedding DFSAdmin in an application whose executor shuts down, or Ctrl-C under wrappers that interrupt threads.","commonSituations":"Safe mode never exits because of missing/under-replicated blocks, and a supervisor timeout kills the wait; systemd stopping the unit; test harnesses cancelling the admin thread; long safe-mode waits after mass datanode loss.","solutions":["Diagnose why safe mode persists first: hdfs dfsadmin -safemode get plus the missing-blocks report (hdfs fsck /), fix blocks or consciously adjust dfs.namenode.safemode.threshold-pct","Re-run -safemode wait once the NN is healthy","If embedding DFSAdmin, catch IOException and restore the flag: Thread.currentThread().interrupt() when the message is 'Wait Interrupted'","Prefer your own bounded poll of setSafeMode(SAFEMODE_GET) with an explicit timeout instead of the blocking CLI wait"],"exampleFix":"// before: blocks forever, loses interruption on shutdown\nadmin.waitExitSafeMode(dfs, true);\n\n// after: bounded poll that preserves interrupt status\nwhile (dfs.setSafeMode(SafeModeAction.SAFEMODE_GET, false) && deadline > now()) {\n  Thread.sleep(5000);\n} // catch InterruptedException: Thread.currentThread().interrupt(); break;","handlingStrategy":"try-catch","validationCode":"null","typeGuard":null,"tryCatchPattern":"try {\n  dfsadmin.run(new String[]{\"-safemode\", \"wait\"});\n} catch (IOException e) {\n  if (\"Wait Interrupted\".equals(e.getMessage())) {\n    Thread.currentThread().interrupt(); // restore the lost interrupt flag\n    throw new ShutdownSignalException(e);\n  }\n  throw e;\n}","preventionTips":["Diagnose safe mode before waiting: -safemode get plus the missing-blocks report","Give -safemode wait an external timeout so supervisors do not have to interrupt it","Never embed the blocking wait in shutdown-sensitive threads; poll SAFEMODE_GET yourself with a deadline"],"tags":["hdfs","dfsadmin","safe-mode","interruption","cli","threading"],"backgroundTag":"thread-interrupted","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}