Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor error handling of failed Node Connections created from the Discovery domain #354

Open
emmacasolin opened this issue Feb 27, 2022 · 0 comments
Labels
development Standard development r&d:polykey:core activity 3 Peer to Peer Federated Hierarchy technology

Comments

@emmacasolin
Copy link
Contributor

Specification

While completing #311 it was discovered that failed node connections created by the Discovery domain (using NodeManager.requestChainData() to get the sigchain data of a node during the discovery process) were not handled correctly, leading to strange errors during testing. A quick fix for handling these errors was implemented, however it could be refactored to be more specific.

Currently we have (inside src/discovery/Discovery.ts):

// Lines 234-246 (requesting chain data from a node in the discovery queue)
try {
  vertexChainData = await this.nodeManager.requestChainData(
    nodeId,
  );
} catch (e) {
  this.visitedVertices.add(vertex);
  await this.removeKeyFromDiscoveryQueue(vertexId);
  this.logger.error(
    `Failed to discover ${vertexGId.nodeId} - ${e.toString()}`,
  );
  yield;
  continue;
}

// Lines 281-302 (requesting chain data from a node that is linked to a node in the discovery queue)
try {
  linkedVertexChainData =
    await this.nodeManager.requestChainData(linkedVertexNodeId);
} catch (e) {
  if (
    e instanceof nodesErrors.ErrorNodeConnectionDestroyed ||
    e instanceof nodesErrors.ErrorNodeConnectionTimeout
  ) {
    if (!this.visitedVertices.has(linkedVertexGK)) {
      await this.pushKeyToDiscoveryQueue(linkedVertexGK);
    }
    this.logger.error(
      `Failed to discover ${nodesUtils.encodeNodeId(
          linkedVertexNodeId,
       )} - ${e.toString()}`,
    );
    yield;
    continue;
  } else {
    throw e;
  }
}

// Lines 367-387 (requesting chain data from a node that is linked to an identity in the discovery queue)
try {
  linkedVertexChainData = await this.nodeManager.requestChainData(
    linkedVertexNodeId,
  );
} catch (e) {
  if (
    e instanceof nodesErrors.ErrorNodeConnectionDestroyed ||
    e instanceof nodesErrors.ErrorNodeConnectionTimeout
  ) {
    if (!this.visitedVertices.has(linkedVertexGK)) {
      await this.pushKeyToDiscoveryQueue(linkedVertexGK);
    }
    yield;
    this.logger.error(
      `Failed to discover ${data.node} - ${e.toString()}`,
    );
    continue;
  } else {
    throw e;
  }
}

Additional context

Tasks

  1. Ensure that in each place in the code only the relevant errors are caught and logged out (i.e. ErrorNodeConnectionDestroyed, ErrorNodeConnectionTimeout, and any other errors found while working through Write tests to cover all possible states of the Discovery, NodeConnection, and discovered Node during the discovery process #349)
  2. Ensure that after an error is caught the order of subsequent actions is (1) log out the error (2) yield (3) continue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
development Standard development r&d:polykey:core activity 3 Peer to Peer Federated Hierarchy technology
Development

No branches or pull requests

4 participants