@@ -994,12 +994,14 @@ bool AppInitParameterInteraction(const ArgsManager& args)
994
994
int nBind = std::max (nUserBind, size_t (1 ));
995
995
// Maximum number of connections with other nodes, this accounts for all types of outbounds and inbounds except for manual
996
996
int user_max_connection = args.GetIntArg (" -maxconnections" , DEFAULT_MAX_PEER_CONNECTIONS);
997
- nMaxConnections = std::max (user_max_connection, 0 );
997
+ if (user_max_connection < 0 ) {
998
+ return InitError (Untranslated (" -maxconnections must be greater or equal than zero" ));
999
+ }
998
1000
// Reserve enough FDs to account for the bare minimum, plus any manual connections, plus the bound interfaces
999
1001
int min_required_fds = MIN_CORE_FDS + MAX_ADDNODE_CONNECTIONS + nBind;
1000
1002
1001
1003
// Try raising the FD limit to what we need (available_fds may be smaller than the requested amount if this fails)
1002
- available_fds = RaiseFileDescriptorLimit (nMaxConnections + min_required_fds);
1004
+ available_fds = RaiseFileDescriptorLimit (user_max_connection + min_required_fds);
1003
1005
// If we are using select instead of poll, our actual limit may be even smaller
1004
1006
#ifndef USE_POLL
1005
1007
available_fds = std::min (FD_SETSIZE, available_fds);
@@ -1008,7 +1010,7 @@ bool AppInitParameterInteraction(const ArgsManager& args)
1008
1010
return InitError (strprintf (_ (" Not enough file descriptors available. %d available, %d required." ), available_fds, min_required_fds));
1009
1011
1010
1012
// Trim requested connection counts, to fit into system limitations
1011
- nMaxConnections = std::min (available_fds - min_required_fds, nMaxConnections );
1013
+ nMaxConnections = std::min (available_fds - min_required_fds, user_max_connection );
1012
1014
1013
1015
if (nMaxConnections < user_max_connection)
1014
1016
InitWarning (strprintf (_ (" Reducing -maxconnections from %d to %d, because of system limitations." ), user_max_connection, nMaxConnections));
0 commit comments