Treat connection limit errors as pending connection errors. #1546
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently connection limit errors emitted by a
Pool
when the per-peer connection limit is reached are emitted asConnectionError
s as soon as background task reports the connection as established, i.e. there is never aConnectionEstablished
event emitted in these cases. This is problematic for two reasons:The
Network
code itself actually relies on an outgoing connection attempt to finish either withPendingConnectionError
orConnectionEstablished
, otherwise there may even be a leak of entries inself.dialing
which never get removed.It actually was the intention that
Network::ConnectionEstablished
events are always paired up 1-1 withNetwork::ConnectionError
events (though the latter should probably be renamed toConnectionClosed
). TheSwarm
relies on this behaviour and mapsConnectionError
toSwarmEvent::ConnectionClosed
, as well as invokingNetworkBehaviour::inject_connection_closed
, which may consequently be invoked for connections for whichinject_connection_established
was never called.In summary, the per-peer connection limit is currently not safe to use. These problems are addressed here by having the
Pool
emit aPendingConnectionError
instead when the limit of established connections of a peer is hit, thus moving theConnectionError::ConnectionLimit
toPendingConnectionError::ConnectionLimit
.This was supposedly observed via an underflowing counter in a network behaviour that tracks the number of established connections via
inject_connection_established
/inject_connection_closed
.I didn't get around yet to write a proper test case for this scenario, which I still intend to do, possibly in a follow-up PR, but since the patch is relatively simple and may want to be released relatively quickly, I'm already opening the PR as-is.