{"record":{"id":"ee0ec9e867fd800e","repo":"apache/hadoop","slug":"filesystem-is-closed-ee0ec9","errorCode":null,"errorMessage":"FileSystem is closed!","messagePattern":"FileSystem is closed!","errorType":"exception","errorClass":"PathIOException","httpStatus":null,"severity":"error","filePath":"hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AFileSystem.java","lineNumber":4428,"sourceCode":"      });\n    } catch (IOException e) {\n      // failure during shutdown.\n      // this should only be from the signature of trackDurationAndSpan().\n      LOG.warn(\"Failure during service shutdown\", e);\n    }\n    // and once this duration has been tracked, close the statistics\n    // other services are shutdown.\n    cleanupWithLogger(LOG, instrumentation);\n  }\n\n  /**\n   * Verify that the filesystem has not been closed. Non blocking; this gives\n   * the last state of the volatile {@link #closed} field.\n   * @throws PathIOException if the FS is closed.\n   */\n  private void checkNotClosed() throws PathIOException {\n    if (isClosed) {\n      throw new PathIOException(uri.toString(), E_FS_CLOSED);\n    }\n  }\n\n  /**\n   * Get the delegation token support for this filesystem;\n   * not null iff delegation support is enabled.\n   * @return the token support, or an empty option.\n   */\n  @VisibleForTesting\n  public Optional<S3ADelegationTokens> getDelegationTokens() {\n    return delegationTokens;\n  }\n\n  /**\n   * Return a service name iff delegation tokens are enabled and the\n   * token binding is issuing delegation tokens.\n   * @return the canonical service name or null\n   */","sourceCodeStart":4410,"sourceCodeEnd":4446,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AFileSystem.java#L4410-L4446","documentation":"Public S3AFileSystem entry points call checkNotClosed(), which throws PathIOException(uri, 'FileSystem is closed!') (E_FS_CLOSED) once the volatile isClosed flag is set by close(). The instance cannot be revived; this is a use-after-close programming error, not a transient condition - no retry will help.","triggerScenarios":"Any FS operation invoked after fs.close() returned; a try-with-resources block on a shared/cached FileSystem closing it while other threads still use it; test teardown closing an instance that later assertions touch.","commonSituations":"Helper methods closing FileSystems they obtained via FileSystem.get() (which returns a shared cached instance); shutdown hooks (FileSystem.closeAllForUGI) racing in-flight work; Spark executors continuing to use a FileSystem after the context stopped.","solutions":["Never close FileSystems obtained from FileSystem.get() - they are cache-shared; only close instances you created with newInstance()","Scope all usage of a FileSystem inside the block that owns it","On this error, discard the reference and obtain a fresh instance with FileSystem.newInstance(uri, conf)"],"exampleFix":"// before: closes the shared cached instance; later users fail\ntry (FileSystem fs = FileSystem.get(uri, conf)) {\n  fs.rename(src, dst);\n}\n\n// after: cached instance is not closed; ownership stays with the cache\nFileSystem fs = FileSystem.get(uri, conf);\nfs.rename(src, dst);\n// or, for explicit lifecycle control:\ntry (FileSystem own = FileSystem.newInstance(uri, conf)) {\n  own.rename(src, dst);\n}","handlingStrategy":"try-catch","validationCode":"// Single-owner wrapper: one place creates and closes the FS\ntry (FileSystem own = FileSystem.newInstance(uri, conf)) {\n  own.rename(src, dst);\n}","typeGuard":"static boolean isFsClosed(PathIOException e) {\n  return \"FileSystem is closed!\".equals(e.getMessage());\n}","tryCatchPattern":"Catch PathIOException, test for the closed message (E_FS_CLOSED), then rebuild the client (FileSystem.newInstance) and fail or retry the operation once with the fresh instance - the old reference is permanently dead.","preventionTips":["Never close FileSystems from FileSystem.get() - they are cache-shared; use newInstance() when you need ownership","Keep all uses of a FileSystem within the scope that owns it","Guard shutdown hooks against racing in-flight operations"],"tags":["s3a","use-after-close","lifecycle","filesystem-cache"],"backgroundTag":"use-after-close","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}