NodeConnectionManager.createConnectionMultiple
should stagger connection attempts to reduce duplicate connections
#653
Labels
development
Standard development
r&d:polykey:core activity 4
End to End Networking behind Consumer NAT Devices
Specification
createConnectionMultiple
is used when we are attempting a direct connection and we have multiple possible addresses to attempt. It is equvalent to doing multiplecreateConnection
calls concurrently with some clean up logic sprinkled on top.It's possible that multiple addresses in the list is valid. In this case we have a race condition where multiple connections are established simultaneously. This is not actually a problem since we fully allow for this. However we want to cut down on duplicate connections if possible.
To this end we need to stagger the connection attempts by some short delay. This will give some grace time for single connections to connect before more are attempted concurrently. If the connections can be established within this delay then only a single connection should be made before we attempt the clean up step.
This should reduce the number of connections fully established concurrently.
I'd say add a test to demonstrate reducing the number of concurrent connections established. But this is a bit indeterminate so we can't really create a test condition for it. Even if it works, It's likely to fail on the CI.
Tasks
staggerDelayTime
parameter to thecreateConnectionMultiple
function.staggerDelayTime
between starting each connection in the list.The text was updated successfully, but these errors were encountered: