xxxDispatcher not marking FileDescriptors as invalid

Radim Vansa rvansa at azul.com
Fri Jan 27 16:05:23 UTC 2023


Hello,

I was experimenting with tracking file descriptors for checkpoint & restore [1] and found that in some cases, using FileDispatcherImpl/UnixDispatcher (depending on JDK version) the java.io.FileDescriptor is not closed properly. While the underlying descriptor is closed the `fd` field in the FileDescriptor object is not set [2] to -1 like the regular FileDescriptor.close0() method would do [3].

Is there any special idea behind that, or is this alternate code path present only as an optimization in case where we know that none of the regular handling would be needed? Is there any risk in unsetting the fd field?

Thank you

Radim Vansa

[1] https://github.com/openjdk/crac
[2] https://github.com/openjdk/jdk/blob/master/src/java.base/unix/native/libnio/ch/UnixDispatcher.c#L58
[3] https://github.com/openjdk/jdk/blob/master/src/java.base/unix/native/libjava/io_util_md.c#L152


More information about the nio-dev mailing list