Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ROS-O] required patches on current systems #2297

Open
wants to merge 12 commits into
base: noetic-devel
Choose a base branch
from
Prev Previous commit
Next Next commit
Disable XmlRpcServer::enoughFreeFDs
The file descriptor hard limit was bumped resulting in each ROS node
allocating 8GB:

https://lists.debian.org/debian-devel/2024/06/msg00041.html
  • Loading branch information
jspricke authored and v4hn committed Oct 14, 2024
commit e4e8ea09ab5525b921e3d43e1d4e76ae625a9acf
64 changes: 0 additions & 64 deletions utilities/xmlrpcpp/src/XmlRpcServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,6 @@ XmlRpcServer::XmlRpcServer()
_accept_error(false),
_accept_retry_time_sec(0.0)
{
#if !defined(_WINDOWS)
struct rlimit limit = { .rlim_cur = 0, .rlim_max = 0 };
unsigned int max_files = 1024;

if(getrlimit(RLIMIT_NOFILE, &limit) == 0) {
max_files = limit.rlim_max;
if( limit.rlim_max == RLIM_INFINITY ) {
max_files = 0;
}
} else {
XmlRpcUtil::error("Could not get open file limit: %s", strerror(errno));
}
pollfds.resize(max_files);
for(unsigned int i=0; i<max_files; i++) {
// Set up file descriptor query for all events.
pollfds[i].fd = i;
pollfds[i].events = POLLIN | POLLPRI | POLLOUT;
}
#endif

// Ask dispatch not to close this socket if it becomes unreadable.
setKeepOpen(true);
}
Expand Down Expand Up @@ -222,51 +202,7 @@ bool XmlRpcServer::enoughFreeFDs() {
// If the underlying system calls here fail, this will print an error and
// return false

#if !defined(_WINDOWS)
int free_fds = 0;

struct rlimit limit = { .rlim_cur = 0, .rlim_max = 0 };

// Get the current soft limit on the number of file descriptors.
if(getrlimit(RLIMIT_NOFILE, &limit) == 0) {
// If we have infinite file descriptors, always return true.
if( limit.rlim_max == RLIM_INFINITY ) {
return true;
}

// Poll the available file descriptors.
// The POSIX specification guarantees that rlim_cur will always be less or
// equal to the process's initial rlim_max, so we don't need an additional
// bounds check here.
if(poll(&pollfds[0], limit.rlim_cur, 1) >= 0) {
for(rlim_t i=0; i<limit.rlim_cur; i++) {
if(pollfds[i].revents & POLLNVAL) {
free_fds++;
}
if (free_fds >= FREE_FD_BUFFER) {
// Checked enough FDs are not opened.
return true;
}
}
} else {
// poll() may fail if interrupted, if the pollfds array is a bad pointer,
// if nfds exceeds RLIMIT_NOFILE, or if the system is out of memory.
XmlRpcUtil::error("XmlRpcServer::enoughFreeFDs: poll() failed: %s",
strerror(errno));
}
} else {
// The man page for getrlimit says that it can fail if the requested
// resource is invalid or the second argument is invalid. I'm not sure
// either of these can actually fail in this code, but it's better to
// check.
XmlRpcUtil::error("XmlRpcServer::enoughFreeFDs: Could not get open file "
"limit, getrlimit() failed: %s", strerror(errno));
}

return false;
#else
return true;
#endif
}


Expand Down
5 changes: 0 additions & 5 deletions utilities/xmlrpcpp/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ if(TARGET test_dispatch_live)
target_link_libraries(test_dispatch_live xmlrpcpp test_fixtures ${Boost_LIBRARIES})
endif()

catkin_add_gtest(test_ulimit test_ulimit.cpp)
if(TARGET test_ulimit)
target_link_libraries(test_ulimit xmlrpcpp test_fixtures ${Boost_LIBRARIES})
endif()

add_library(mock_socket mock_socket.cpp)
target_link_libraries(mock_socket ${GTEST_LIBRARIES})
set_target_properties(mock_socket PROPERTIES EXCLUDE_FROM_ALL TRUE)
Expand Down
82 changes: 0 additions & 82 deletions utilities/xmlrpcpp/test/test_ulimit.cpp

This file was deleted.