aboutsummaryrefslogtreecommitdiff
path: root/src/init.cpp
diff options
context:
space:
mode:
authorSergi Delgado Segura <sergi.delgado.s@gmail.com>2024-05-08 15:27:55 -0400
committerSergi Delgado Segura <sergi.delgado.s@gmail.com>2024-09-05 11:43:46 -0400
commit29008a7ff43cf712a8438663e79cebdf698efae9 (patch)
tree5c6b3a720c51b25d1410edf869447a767cc9e206 /src/init.cpp
parentd661e2b1b771abafb0b152842d775d3150032230 (diff)
init: fixes fd accounting regarding poll/select
We are computing our file descriptors limits based on whether we use poll or select. However, we are taking that into account only partially (subtracting from fd_max in one case, but from nFD later on). Moreover, nBind is also only accounted for partially. Simplify and fix this logic
Diffstat (limited to 'src/init.cpp')
-rw-r--r--src/init.cpp16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/init.cpp b/src/init.cpp
index e60feecf10..d280ef905a 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -993,18 +993,16 @@ bool AppInitParameterInteraction(const ArgsManager& args)
nMaxConnections = std::max(nUserMaxConnections, 0);
nFD = RaiseFileDescriptorLimit(nMaxConnections + MIN_CORE_FILEDESCRIPTORS + MAX_ADDNODE_CONNECTIONS + nBind + NUM_FDS_MESSAGE_CAPTURE);
-
-#ifdef USE_POLL
- int fd_max = nFD;
-#else
- int fd_max = FD_SETSIZE;
+ // If we are using select instead of poll, our actual limit may be even smaller
+#ifndef USE_POLL
+ nFD = std::min(FD_SETSIZE, nFD);
#endif
- // Trim requested connection counts, to fit into system limitations
- // <int> in std::min<int>(...) to work around FreeBSD compilation issue described in #2695
- nMaxConnections = std::max(std::min<int>(nMaxConnections, fd_max - nBind - MIN_CORE_FILEDESCRIPTORS - MAX_ADDNODE_CONNECTIONS - NUM_FDS_MESSAGE_CAPTURE), 0);
if (nFD < MIN_CORE_FILEDESCRIPTORS)
return InitError(_("Not enough file descriptors available."));
- nMaxConnections = std::min(nFD - MIN_CORE_FILEDESCRIPTORS - MAX_ADDNODE_CONNECTIONS - NUM_FDS_MESSAGE_CAPTURE, nMaxConnections);
+
+ // Trim requested connection counts, to fit into system limitations
+ // <int> in std::min<int>(...) to work around FreeBSD compilation issue described in #2695
+ nMaxConnections = std::max(std::min<int>(nMaxConnections, nFD - nBind - MIN_CORE_FILEDESCRIPTORS - MAX_ADDNODE_CONNECTIONS - NUM_FDS_MESSAGE_CAPTURE), 0);
if (nMaxConnections < nUserMaxConnections)
InitWarning(strprintf(_("Reducing -maxconnections from %d to %d, because of system limitations."), nUserMaxConnections, nMaxConnections));