Skip to content

Reduce the timeout for establishing a Node Connection within the Discovery domain (by adding timer override to NodeConnectionManager) #353

@emmacasolin

Description

@emmacasolin

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:

  1. The chosen timeout must be set as a constant property of the Discovery class
  2. NodeManager.requestChainData() needs to have an extra parameter for this timeout (alternatively, since this requestChainData() method is not used anywhere else outside of Discovery we could move it into the Discovery class and methods called by it could just directly use the Discovery's timeout property)
  3. NodeConnectionManager.withConnF() (called by requestChainData()) needs an additional timeout parameter
  4. NodeConnectionManager.acquireConnection() (called by withConnF()) needs an additional timeout parameter
  5. NodeConnectionManager.createConnection() (called by acquireConnection()) needs an additional timeout parameter
  6. NodeConnectionManager.establishNodeConnection() (called by createConnection()) needs an additional timeout parameter which defaults to NodeConnectionManager.connConnectTime if not set explicitly - all instances of using NodeConnectionManager.connConnectTime inside this method need to switch over to using this parameter instead

Additional context

Tasks

  1. Create a timeout property for the Discovery class (around 1000-2000ms)
  2. Propagate this timeout through the relevant methods to the establishment of a node connection

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions