Skip to content

Commit 91a9fb5

Browse files
Fix a crash on startup when ulimits are set to unlimited.
1 parent 6a95ceb commit 91a9fb5

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/init.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
#include "llmq/quorums_init.h"
6363

6464
#include <stdint.h>
65+
#include <sys/resource.h>
6566
#include <stdio.h>
6667
#include <memory>
6768

@@ -1070,9 +1071,9 @@ void InitLogging() {
10701071
namespace { // Variables internal to initialization process only
10711072

10721073
ServiceFlags nRelevantServices = NODE_NETWORK;
1073-
int nMaxConnections;
1074-
int nUserMaxConnections;
1075-
int nFD;
1074+
rlim_t nMaxConnections;
1075+
rlim_t nUserMaxConnections;
1076+
rlim_t nFD;
10761077
ServiceFlags nLocalServices = NODE_NETWORK;
10771078

10781079
}
@@ -1168,10 +1169,10 @@ bool AppInitParameterInteraction()
11681169
(mapMultiArgs.count("-bind") ? mapMultiArgs.at("-bind").size() : 0) +
11691170
(mapMultiArgs.count("-whitebind") ? mapMultiArgs.at("-whitebind").size() : 0), size_t(1));
11701171
nUserMaxConnections = GetArg("-maxconnections", DEFAULT_MAX_PEER_CONNECTIONS);
1171-
nMaxConnections = std::max(nUserMaxConnections, 0);
1172+
nMaxConnections = std::max(nUserMaxConnections, (rlim_t)0);
11721173

11731174
// Trim requested connection counts, to fit into system limitations
1174-
nMaxConnections = std::max(std::min(nMaxConnections, (int)(FD_SETSIZE - nBind - MIN_CORE_FILEDESCRIPTORS - MAX_ADDNODE_CONNECTIONS)), 0);
1175+
nMaxConnections = std::max(std::min(nMaxConnections, (rlim_t)(FD_SETSIZE - nBind - MIN_CORE_FILEDESCRIPTORS - MAX_ADDNODE_CONNECTIONS)), (rlim_t)0);
11751176
nFD = RaiseFileDescriptorLimit(nMaxConnections + MIN_CORE_FILEDESCRIPTORS + MAX_ADDNODE_CONNECTIONS);
11761177
if (nFD < MIN_CORE_FILEDESCRIPTORS)
11771178
return InitError(_("Not enough file descriptors available."));

0 commit comments

Comments
 (0)