Skip to content

Conversation

maflcko
Copy link
Member

@maflcko maflcko commented Oct 24, 2016

nMaxInbound might very well be 0 or -1, if the user prefers to keep
a small number of maxconnections.

Note: nMaxInbound of -1 means that the user set maxconnections
to 8 or less, but we still want to keep an additional slot for
the feeler connection.

Closes #9007

nMaxInbound might very well be 0 or -1, if the user prefers to keep
a small number of maxconnections.

Note: nMaxInbound of -1 means that the user set maxconnections
to 8 or less, but we still want to keep an additional slot for
the feeler connection.
@maflcko maflcko added the P2P label Oct 24, 2016
@maflcko maflcko added this to the 0.13.1 milestone Oct 24, 2016
@sipa
Copy link
Member

sipa commented Oct 24, 2016

Isn't there some behaviour we want when the actual value (based on number of connections, not maximum number) <= 0, like cancelling the attempt?

@laanwj
Copy link
Member

laanwj commented Oct 25, 2016

Isn't there some behaviour we want when the actual value (based on number of connections, not maximum number) <= 0, like cancelling the attempt?

I've checked the code below it and I think there is no danger from this value reaching <0. The only thing that actually uses nMaxInBound is:

    if (nInbound >= nMaxInbound)
    {
        if (!AttemptToEvictConnection()) {
            // No connection to evict, disconnect the new connection
            LogPrint("net", "failed to find an eviction candidate - connection dropped (full)\n");
            CloseSocket(hSocket);
            return;
        }
    }

So it will try to evict all connections, just like when nMaxInbound would be 0, which I think makes sense. No need for special-casing.

utACK fa1c3c2

@@ -970,7 +970,6 @@ void CConnman::AcceptConnection(const ListenSocket& hListenSocket) {
CAddress addr;
int nInbound = 0;
int nMaxInbound = nMaxConnections - (nMaxOutbound + nMaxFeeler);
Copy link
Member

@laanwj laanwj Oct 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be wise to cap this to 0 explicitly, as no one will be expecting this to be negative in future maintenance, and they may add something again that crashes if it is.

int nMaxInbound = std::max(nMaxConnections - (nMaxOutbound + nMaxFeeler), 0);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree at just blindly capping this at 0. There are only two ways imo:

  • Add a comment which says this may be negative
  • Rework the "-maxconnections" code to not allow negative numbers here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think a negative value for something called nMaxOutbound makes sense. There should never be a difference in behavior between no outgoing connections, or negative outgoing connections. But ok, this needs a different solution anyway at a higher level.

@laanwj
Copy link
Member

laanwj commented Oct 25, 2016

Theoretically we could stop listening for inbound connections completely if this is <=0, however, whitelisted connections are probably an exception? There are some potential traps there that can create additional unexpected behavior changes. I think this pull is safe and we can do that later.

@gmaxwell
Copy link
Contributor

Theoretically we could stop listening for inbound connections completely if this is <=0, however, whitelisted connections are probably an exception?

Probably the logic should be changed further in the future, if you set maxconnections to 5 and -listen=1 -connect=gateway.host I would expect you to end up with 5 connections, not 1.

But ACK getting rid of the assert, good move for now and telling people to set maxconnections to a small number used to be common advice for people concerned with memory and bandwidth (we now use less memory per peer, so less reason)... I also checked that the negative is fine with the current code.

@laanwj laanwj merged commit fa1c3c2 into bitcoin:master Oct 25, 2016
laanwj added a commit that referenced this pull request Oct 25, 2016
fa1c3c2 [net] Remove assert(nMaxInbound > 0) (MarcoFalke)
laanwj pushed a commit that referenced this pull request Oct 25, 2016
nMaxInbound might very well be 0 or -1, if the user prefers to keep
a small number of maxconnections.

Note: nMaxInbound of -1 means that the user set maxconnections
to 8 or less, but we still want to keep an additional slot for
the feeler connection.

Github-Pull: #9008
Rebased-From: fa1c3c2
@maflcko maflcko deleted the Mf1610-netAssert branch October 25, 2016 17:46
sickpig referenced this pull request in sickpig/BitcoinUnlimited Apr 14, 2017
fa1c3c2 [net] Remove assert(nMaxInbound > 0) (MarcoFalke)
lateminer pushed a commit to lateminer/bitcoin that referenced this pull request Oct 18, 2018
nMaxInbound might very well be 0 or -1, if the user prefers to keep
a small number of maxconnections.

Note: nMaxInbound of -1 means that the user set maxconnections
to 8 or less, but we still want to keep an additional slot for
the feeler connection.

Github-Pull: bitcoin#9008
Rebased-From: fa1c3c2
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Assertion failed: (nMaxInbound > 0), function AcceptConnection, file net.cpp, line 973.
4 participants