-
Notifications
You must be signed in to change notification settings - Fork 5
Description
Specification
The default timeout for node connections is currently set inside the NodeConnectionManager for 20s. This can only be set when creating a new Polykey agent by setting the nodeConnectionManagerConfig when calling PolykeyAgent.createPolykeyAgent():
// From src/config.defaults
nodeConnectionManagerConfig: {
connConnectTime: 20000, // this is the relevant setting
connTimeoutTime: 60000,
initialClosestNodes: 3,
},This value is subsequently used for all node connections, regardless of what the node connection is used for or where it originates from. This is a problem for the Discovery domain, where a default timeout of 20s is too long. The Discovery domain calls NodeManager.requestChainData(), which calls NodeConnectionManager.withConnF(), which subsequently creates the node connection that we use. We need to be able to change the timeout for creating this node connection from inside the Discovery domain to something smaller, for example 1-2s. This does not need to be a modifiable option that is available to the user, since it should not affect the behaviour of the Discovery domain, so the timeout can just be a constant.
In order for the Discovery domain to be able to set its own timeout for Node Connections, we need to propagate the timeout through a few different places in the code. Specifically:
- The chosen timeout must be set as a constant property of the
Discoveryclass NodeManager.requestChainData()needs to have an extra parameter for this timeout (alternatively, since thisrequestChainData()method is not used anywhere else outside ofDiscoverywe could move it into theDiscoveryclass and methods called by it could just directly use theDiscovery's timeout property)NodeConnectionManager.withConnF()(called byrequestChainData()) needs an additionaltimeoutparameterNodeConnectionManager.acquireConnection()(called bywithConnF()) needs an additionaltimeoutparameterNodeConnectionManager.createConnection()(called byacquireConnection()) needs an additionaltimeoutparameterNodeConnectionManager.establishNodeConnection()(called bycreateConnection()) needs an additionaltimeoutparameter which defaults toNodeConnectionManager.connConnectTimeif not set explicitly - all instances of usingNodeConnectionManager.connConnectTimeinside this method need to switch over to using this parameter instead
Additional context
- Old issue for handling exceptions during Node Connection timeouts: Ensure that exceptions during Discovery are correctly handled #348
Tasks
- Create a
timeoutproperty for theDiscoveryclass (around 1000-2000ms) - Propagate this timeout through the relevant methods to the establishment of a node connection