Skip to content

Commit 7c91ace

Browse files
committed
fix: async bug with composing connections
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.
1 parent 856388b commit 7c91ace

3 files changed

Lines changed: 3 additions & 2 deletions

File tree

src/network/ConnectionReverse.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ class ConnectionReverse extends Connection {
217217
if (this._composed) {
218218
throw new networkErrors.ErrorConnectionComposed();
219219
}
220-
this._composed = true;
221220
this.logger.info('Composing Connection Reverse');
222221
// Promise for secure establishment
223222
const { p: secureP, resolveP: resolveSecureP } = promise<void>();
@@ -306,6 +305,7 @@ class ConnectionReverse extends Connection {
306305
});
307306
this.clientCertChain = clientCertChain;
308307
this.logger.info('Composed Connection Reverse');
308+
this._composed = true;
309309
} catch (e) {
310310
this._composed = false;
311311
throw e;

src/nodes/NodeConnection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class NodeConnection<T extends GRPCClient> {
128128
},
129129
timer: timer,
130130
}),
131-
holePunchPromises,
131+
...holePunchPromises,
132132
]);
133133
// 5. When finished, you have a connection to other node
134134
// The GRPCClient is ready to be used for requests

src/nodes/NodeConnectionManager.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,7 @@ class NodeConnectionManager {
756756
const signature = await this.keyManager.signWithRootKeyPair(
757757
Buffer.from(proxyAddress),
758758
);
759+
// FIXME: this needs to handle aborting
759760
const holePunchPromises = Array.from(this.getSeedNodes(), (seedNodeId) => {
760761
return this.sendHolePunchMessage(
761762
seedNodeId,

0 commit comments

Comments
 (0)