Skip to content

community/openjdk8: remove close-fd workaround again

Remove this workaroudn and use opendir() on /proc/self/fd again.

This fixes an issue on our internal build server, where the openfiles ulimit was at 1bn, causing a single Runtime.exec() to take over 9 seconds. This patch should not be needed any longer, as the java 9+ aports didn't include it in the first place and seem to run just fine.

After digging into this issue using strace, a single Runtime.exec() caused a logfile with 1.8G with thousands of poll() calls, before executing the requested comand (/bin/ps in this example):

142   poll([{fd=1073740804, events=0}, {fd=1073740805, events=0}, {fd=1073740806, events=0}, {fd=1073740807, events=0}, {fd=1073740808, events=0}, {fd=1073740809, events=0}, {fd=1073740810, events=0}, {fd=1073740811, events=0}, {fd=1073740812, events=0}, {fd=1073740813, events=0}, {fd=1073740814, events=0}, {fd=1073740815, events=0}, {fd=1073740816, events=0}, {fd=1073740817, events=0}, {fd=1073740818, events=0}, {fd=1073740819, events=0}, {fd=1073740820, events=0}, {fd=1073740821, events=0}, {fd=1073740822, events=0}, {fd=1073740823, events=0}, {fd=1073740824, events=0}, {fd=1073740825, events=0}, {fd=1073740826, events=0}, {fd=1073740827, events=0}, {fd=1073740828, events=0}, {fd=1073740829, events=0}, {fd=1073740830, events=0}, {fd=1073740831, events=0}, {fd=1073740832, events=0}, {fd=1073740833, events=0}, {fd=1073740834, events=0}, {fd=1073740835, events=0}, ...], 1012, 0) = 1012 ([{fd=1073740804, revents=POLLNVAL}, {fd=1073740805, revents=POLLNVAL}, {fd=1073740806, revents=POLLNVAL}, {fd=1073740807, revents=POLLNVAL}, {fd=1073740808, revents=POLLNVAL}, {fd=1073740809, revents=POLLNVAL}, {fd=1073740810, revents=POLLNVAL}, {fd=1073740811, revents=POLLNVAL}, {fd=1073740812, revents=POLLNVAL}, {fd=1073740813, revents=POLLNVAL}, {fd=1073740814, revents=POLLNVAL}, {fd=1073740815, revents=POLLNVAL}, {fd=1073740816, revents=POLLNVAL}, {fd=1073740817, revents=POLLNVAL}, {fd=1073740818, revents=POLLNVAL}, {fd=1073740819, revents=POLLNVAL}, {fd=1073740820, revents=POLLNVAL}, {fd=1073740821, revents=POLLNVAL}, {fd=1073740822, revents=POLLNVAL}, {fd=1073740823, revents=POLLNVAL}, {fd=1073740824, revents=POLLNVAL}, {fd=1073740825, revents=POLLNVAL}, {fd=1073740826, revents=POLLNVAL}, {fd=1073740827, revents=POLLNVAL}, {fd=1073740828, revents=POLLNVAL}, {fd=1073740829, revents=POLLNVAL}, {fd=1073740830, revents=POLLNVAL}, {fd=1073740831, revents=POLLNVAL}, ...])
142   fcntl(3, F_SETFD, FD_CLOEXEC)     = 0
142   execve("/bin/ps", ["/bin/ps"], 0x7ffc44a10ea0 /* 7 vars */) = 0

Debugging with gdb I've found the cause at:

(gdb) bt
#0  __cp_end () at src/thread/x86_64/syscall_cp.s:29
#1  0x00007fd286b095b7 in __syscall_cp_c (nr=7, u=<optimized out>, v=<optimized out>, w=<optimized out>, x=<optimized out>, y=<optimized out>, z=0) at src/thread/pthread_cancel.c:33
#2  0x00007fd286afd08d in poll (fds=fds@entry=0x7fd285a13fb0, n=n@entry=1024, timeout=timeout@entry=0) at src/select/poll.c:9
#3  0x00007fd2858edb07 in poll (__s=0, __n=<optimized out>, __f=0x7fd285a13fb0) at /usr/include/fortify/poll.h:39
#4  closeDescriptors () at /home/buildozer/aports/community/openjdk8/src/icedtea-3.29.0/openjdk/jdk/src/solaris/native/java/lang/childproc.c:87
#5  0x00007fd2858ee196 in childProcess (arg=arg@entry=0x7fd26b76f5e0) at /home/buildozer/aports/community/openjdk8/src/icedtea-3.29.0/openjdk/jdk/src/solaris/native/java/lang/childproc.c:337
#6  0x00007fd2858eb848 in forkChild (c=0x7fd26b76f5e0) at /home/buildozer/aports/community/openjdk8/src/icedtea-3.29.0/openjdk/jdk/src/solaris/native/java/lang/UNIXProcess_md.c:454
#7  startChild (env=0x7fd2858c2a60, process=<optimized out>, helperpath=0x7fd26b4a9d50 "/usr/lib/jvm/java-1.8-openjdk/jre/lib/amd64/jspawnhelper", c=0x7fd26b76f5e0)
    at /home/buildozer/aports/community/openjdk8/src/icedtea-3.29.0/openjdk/jdk/src/solaris/native/java/lang/UNIXProcess_md.c:559
#8  Java_java_lang_UNIXProcess_forkAndExec (env=0x7fd2858c2a60, process=<optimized out>, mode=<optimized out>, helperpath=0x7fd285a161a8, prog=0x7fd285a161a0, argBlock=0x7fd285a16198, argc=0, envBlock=0x0, envc=0, dir=0x0, std_fds=0x7fd285a16170,
    redirectErrorStream=0 '\000') at /home/buildozer/aports/community/openjdk8/src/icedtea-3.29.0/openjdk/jdk/src/solaris/native/java/lang/UNIXProcess_md.c:650
#9  0x00007fd2768c1427 in ?? ()
#10 0x0000000000000000 in ?? ()

This clearly shows that the issue is caused by the patch I'd like to remove.

Edited by Simon F

Merge request reports