Skip to content

Commit

Permalink
fix: async bug with composing connections
Browse files Browse the repository at this point in the history
the composed flag was set at the beginning of the compose function causing another function to throw an error due to an undefined property if it was called at the same time.
  • Loading branch information
tegefaulkes committed Jun 24, 2022
1 parent 856388b commit 7c91ace
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/network/ConnectionReverse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ class ConnectionReverse extends Connection {
if (this._composed) {
throw new networkErrors.ErrorConnectionComposed();
}
this._composed = true;
this.logger.info('Composing Connection Reverse');
// Promise for secure establishment
const { p: secureP, resolveP: resolveSecureP } = promise<void>();
Expand Down Expand Up @@ -306,6 +305,7 @@ class ConnectionReverse extends Connection {
});
this.clientCertChain = clientCertChain;
this.logger.info('Composed Connection Reverse');
this._composed = true;
} catch (e) {
this._composed = false;
throw e;
Expand Down
2 changes: 1 addition & 1 deletion src/nodes/NodeConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class NodeConnection<T extends GRPCClient> {
},
timer: timer,
}),
holePunchPromises,
...holePunchPromises,
]);
// 5. When finished, you have a connection to other node
// The GRPCClient is ready to be used for requests
Expand Down
1 change: 1 addition & 0 deletions src/nodes/NodeConnectionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,7 @@ class NodeConnectionManager {
const signature = await this.keyManager.signWithRootKeyPair(
Buffer.from(proxyAddress),
);
// FIXME: this needs to handle aborting
const holePunchPromises = Array.from(this.getSeedNodes(), (seedNodeId) => {
return this.sendHolePunchMessage(
seedNodeId,
Expand Down

0 comments on commit 7c91ace

Please sign in to comment.