-
-
Notifications
You must be signed in to change notification settings - Fork 530
Open
Labels
Description
Describe the bug
On a system with and incredibly high RLIMIT_NOFILE
, establishing a connection can take minutes.
To Reproduce
- Start x11vnc
- Increase RLIMIT_NOFILE with something like
prlimit -n1073741816 -p $(pidof x11vnc)
- Connect to x11vnc with a vnc client
- Observe that the connection takes incredibly long to establish.
Expected Behavior
The connection speed should be independent from this limit but the following code iterates through each fd instead:
libvncserver/src/libvncserver/sockets.c
Lines 508 to 527 in 784cccb
#if defined LIBVNCSERVER_HAVE_SYS_RESOURCE_H && defined LIBVNCSERVER_HAVE_FCNTL_H | |
if(getrlimit(RLIMIT_NOFILE, &rlim) < 0) | |
maxfds = 100; /* use a sane default if getting the limit fails */ | |
else | |
maxfds = rlim.rlim_cur; | |
/* get the number of currently open fds as per https://stackoverflow.com/a/7976880/361413 */ | |
curfds = 0; | |
for(i = 0; i < maxfds; ++i) | |
if(fcntl(i, F_GETFD) != -1) | |
++curfds; | |
if(curfds > maxfds * rfbScreen->fdQuota) { | |
rfbErr("rfbProcessNewconnection: open fd count of %lu exceeds quota %.1f of limit %lu, denying connection\n", curfds, rfbScreen->fdQuota, maxfds); | |
sock = accept(chosen_listen_sock, NULL, NULL); | |
rfbCloseSocket(sock); | |
return FALSE; | |
} | |
#endif | |
Through a current bug with docker/containerd systemd integration, the docker context inherits this incredibly high limit. This will eventually be fixed, but I still wanted to open an issue about this here since the limit may be set high intentionally. Here's some prior art about the same issue in fakeroot
. https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=920913