RFR: 8367561: Getting some "header" property from a file:// URL causes a file descriptor leak [v3]
Daniel Fuchs
dfuchs at openjdk.org
Wed Oct 8 13:25:58 UTC 2025
On Wed, 8 Oct 2025 13:19:52 GMT, Daniel Fuchs <dfuchs at openjdk.org> wrote:
>> I had a look at the FileURLConnection hierarchy and the FileInputStream class. None of those have a finalize() nor any cleaners. Which would mean that even if these objects were garbage collected, the underlying file descriptor (used by FileInputStream) would still be open. Having said that, I haven't checked older releases (to which this might get backported). So I've added a `ReachabilityFence` for the `URLConnection` instance.
>
> If I'm not mistaken at least FileInputStream has a cleaner to close its file descriptor:
> https://github.com/openjdk/jdk/blob/23fcbb0badbef6d22f63ca6c5b26b0693002592c/src/java.base/share/classes/java/io/FileInputStream.java#L140
Thanks for adding the reachability fence. An other possibility would have been to temporarily stash `conn` in a static field.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/27633#discussion_r2413852147
More information about the net-dev
mailing list