RFC on 8165823: (se) EPollArrayWrapper throws NPE if limits.conf set to 65536 and fd=65536
Brian Burkhalter
brian.burkhalter at oracle.com
Mon Oct 3 23:58:30 UTC 2016
Either my reasoning based on code inspection is faulty or there is something fishy about this bug report [1].
If the maximum number of open file descriptors is set to 65536 by ulimit -n, in limits.conf, or some other means it looks like the range of allowed file descriptors should be [0,65535]. In EPollArrayWrapper [2] the array of fds has size
MAX_UPDATE_ARRAY_SIZE = min(OPEN_MAX,64*1024)
(lines 83-84) where OPEN_MAX is the value of the rlim_max member of the struct rlimit set by a call to getrlimit() [3] (line 73). The getrlimit() system call for resource RLIMIT_NOFILE is specified to return “one greater than the maximum file descriptor number that can be opened by this process.” In this case OPEN_MAX should be 65536 which is 64*1024 so that MAX_UPDATE_ARRAY_SIZE is 65536 hence equal to OPEN_MAX and the eventsHigh HashMap in EPollArrayWrapper is not initialized (line 138). Then if the maximum allowed fd for the process should not exceed 65535, the fd parameter of EPollArrayWrapper.setUpdateEvents() (line 183) should not exceed 65535 which is less than MAX_UPDATE_ARRAY_SIZE (65536) so the branch which uses the eventsHigh map (line 189) should never be entered.
What seems to be a more likely scenario for the NPE failure is that the resource limit on the number of open file descriptors is being changed to a value greater than MAX_UPDATE_ARRAY_SIZE *after* the EPollArrayWrapper instance is constructed which would mean that setUpdateEvents() could in fact receive an fd parameter greater than MAX_UPDATE_ARRAY_SIZE and an NPE due to a null eventsHigh would ensue.
Comments welcome.
Thanks,
Brian
[1] https://bugs.openjdk.java.net/browse/JDK-8165823
[2] http://hg.openjdk.java.net/jdk9/dev/jdk/file/2a474d0ba36d/src/java.base/linux/classes/sun/nio/ch/EPollArrayWrapper.java
[3] http://manpages.ubuntu.com/manpages/xenial/man2/getrlimit.2.html
More information about the nio-dev
mailing list