Skip to content

GH-1067: Close cached HDFS FileSystem instances - #1141

Open
xborder wants to merge 2 commits into
apache:mainfrom
xborder:gh-1067
Open

GH-1067: Close cached HDFS FileSystem instances#1141
xborder wants to merge 2 commits into
apache:mainfrom
xborder:gh-1067

Conversation

@xborder

@xborder xborder commented May 7, 2026

Copy link
Copy Markdown
Contributor

What's Changed

  • This PR fixes JVM shutdown hangs after reading HDFS datasets through Arrow Java.
  • FileSystemDatasetFactory now tracks hdfs:// URIs used to create the factory. On close(), after releasing the native dataset factory, it best-effort closes the matching Hadoop FileSystem instances.
  • The Hadoop cleanup is done via reflection so Arrow Java does not add a production dependency on Hadoop. Non-HDFS URIs are ignored.

Closes #1067 .

@github-actions

This comment has been minimized.

@jbonofre jbonofre added this to the 20.0.0 milestone May 7, 2026
@jbonofre jbonofre added the bug-fix PRs that fix a big. label May 7, 2026
@jbonofre

Copy link
Copy Markdown
Member

@xborder I fixed the CI on main. Can you please rebase?

@lidavidm

Copy link
Copy Markdown
Member

Sorry, probably need to rebase again.

@xborder

xborder commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

done @lidavidm

Comment on lines +73 to +77
try {
super.close();
} finally {
hdfsFileSystems.forEach(FileSystemDatasetFactory::closeHadoopFileSystem);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could we use AutoCloseables here?

Method closeMethod = fsClass.getMethod("close");
closeMethod.invoke(fs);
} catch (Exception e) {
// Best-effort cleanup; Hadoop may not be on classpath or FileSystem already closed

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: worth perhaps logging this?

Comment on lines +103 to +104
} catch (Exception e) {
// Ignore here; native factory creation reports invalid user URIs.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could we catch a more specific exception class for invalid URIs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug-fix PRs that fix a big.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ARROW Java][HDFS] JVM hangs after reading HDFS files via Arrow Dataset API due to non-daemon native threads

3 participants