RFC on 8165823: (se) EPollArrayWrapper throws NPE if limits.conf set to 65536 and fd=65536
Langer, Christoph
christoph.langer at sap.com
Tue Oct 4 07:44:41 UTC 2016
Hi Brian,
I agree to your code analysis, that for a ulimit value of 65536 still the NPE should not occur, assuming the fd number can't be higher than 65535. However, is there a guarantee about the file descriptor numbers themselves being in the range between 0 and OPEN_MAX - 1? Maybe just the count of open file descriptors has to be in the OPEN_MAX range but single number values could well be out of that range? At least on certain operating systems?
I remember Thomas has just recently done some work in the area of file descriptors: @Thomas: Do you have anything to add here?
Best regards
Christoph
> -----Original Message-----
> From: nio-dev [mailto:nio-dev-bounces at openjdk.java.net] On Behalf Of Brian
> Burkhalter
> Sent: Dienstag, 4. Oktober 2016 01:59
> To: nio-dev <nio-dev at openjdk.java.net>
> Subject: RFC on 8165823: (se) EPollArrayWrapper throws NPE if limits.conf set
> to 65536 and fd=65536
>
> 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