From f72ba31091a807fdfb7883c0d5ddd7bb7ea2a06c Mon Sep 17 00:00:00 2001 From: Brian Botha Date: Mon, 16 Jun 2025 15:44:25 +1000 Subject: [PATCH 1/3] fix: fixed potential leak of setNode error --- src/nodes/NodeManager.ts | 71 +++++++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 30 deletions(-) diff --git a/src/nodes/NodeManager.ts b/src/nodes/NodeManager.ts index 486d1389f..e98e1afda 100644 --- a/src/nodes/NodeManager.ts +++ b/src/nodes/NodeManager.ts @@ -310,7 +310,7 @@ class NodeManager { connectedTime: Date.now(), scopes: ['global'], }, - true, + false, false, ); }; @@ -925,7 +925,7 @@ class NodeManager { }); } - if (!connectionMade) { + if (connectionMade == null) { throw new nodesErrors.ErrorNodeManagerFindNodeFailed( 'failed to find node via direct', ); @@ -1312,8 +1312,8 @@ class NodeManager { @decorators.context ctx: ContextTimed, ): Promise { if (tran == null) { - return this.db.withTransactionF((tran) => { - return this.claimNode(targetNodeId, tran); + return await this.db.withTransactionF(async (tran) => { + return await this.claimNode(targetNodeId, tran); }); } const [, claim] = await this.sigchain.addClaim( @@ -1515,8 +1515,9 @@ class NodeManager { tran?: DBTransaction, ): Promise> { if (tran == null) { - return this.db.withTransactionF((tran) => - this.handleClaimNetwork(requestingNodeId, input, tran), + return await this.db.withTransactionF( + async (tran) => + await this.handleClaimNetwork(requestingNodeId, input, tran), ); } const signedClaim = claimsUtils.parseSignedClaim(input.signedTokenEncoded); @@ -1546,8 +1547,9 @@ class NodeManager { tran?: DBTransaction, ): Promise> { if (tran == null) { - return this.db.withTransactionF((tran) => - this.handleVerifyClaimNetwork(requestingNodeId, input, tran), + return await this.db.withTransactionF( + async (tran) => + await this.handleVerifyClaimNetwork(requestingNodeId, input, tran), ); } const signedClaim = claimsUtils.parseSignedClaim(input.signedTokenEncoded); @@ -1680,17 +1682,18 @@ class NodeManager { } if (tran == null) { - return this.db.withTransactionF((tran) => - this.setNode( - nodeId, - nodeAddress, - nodeContactAddressData, - block, - force, - connectionConnectTimeoutTime, - tran, - ctx, - ), + return await this.db.withTransactionF( + async (tran) => + await this.setNode( + nodeId, + nodeAddress, + nodeContactAddressData, + block, + force, + connectionConnectTimeoutTime, + tran, + ctx, + ), ); } @@ -1824,13 +1827,14 @@ class NodeManager { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.db.withTransactionF((tran) => - this.garbageCollectBucket( - bucketIndex, - connectionConnectTimeoutTime, - ctx, - tran, - ), + return await this.db.withTransactionF( + async (tran) => + await this.garbageCollectBucket( + bucketIndex, + connectionConnectTimeoutTime, + ctx, + tran, + ), ); } @@ -2041,8 +2045,8 @@ class NodeManager { protected async setupRefreshBucketTasks(tran?: DBTransaction) { if (tran == null) { - return this.db.withTransactionF((tran) => - this.setupRefreshBucketTasks(tran), + return await this.db.withTransactionF( + async (tran) => await this.setupRefreshBucketTasks(tran), ); } @@ -2149,8 +2153,15 @@ class NodeManager { @decorators.context ctx: ContextTimed, ): Promise { if (tran == null) { - return this.db.withTransactionF((tran) => - this.updateRefreshBucketDelay(bucketIndex, delay, lazy, tran, ctx), + return await this.db.withTransactionF( + async (tran) => + await this.updateRefreshBucketDelay( + bucketIndex, + delay, + lazy, + tran, + ctx, + ), ); } From 77b7882793c0c8cf0cdbcb6468bd2bb3c8aee7fd Mon Sep 17 00:00:00 2001 From: Brian Botha Date: Mon, 16 Jun 2025 16:53:41 +1000 Subject: [PATCH 2/3] fix: fixed leaking timeout error during `nodesFind` --- src/nodes/NodeManager.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/nodes/NodeManager.ts b/src/nodes/NodeManager.ts index e98e1afda..e85de4dec 100644 --- a/src/nodes/NodeManager.ts +++ b/src/nodes/NodeManager.ts @@ -707,7 +707,6 @@ class NodeManager { } while (true) { - ctx.signal.throwIfAborted(); const isDone = await nodeConnectionsQueue.withNodeSignal( async (nodeIdTarget, nodeIdSignaller) => { let nodeConnection: NodeConnection | undefined; @@ -849,7 +848,6 @@ class NodeManager { } while (true) { - ctx.signal.throwIfAborted(); const isDone = await nodeConnectionsQueue.withNodeDirect( async (nodeIdTarget, nodeContact) => { if (!this.nodeConnectionManager.hasConnection(nodeIdTarget)) { @@ -924,8 +922,7 @@ class NodeManager { throw e; }); } - - if (connectionMade == null) { + if (!connectionMade) { throw new nodesErrors.ErrorNodeManagerFindNodeFailed( 'failed to find node via direct', ); From 71a84730272e2eed5fd825a5da69fc7853520a1d Mon Sep 17 00:00:00 2001 From: Brian Botha Date: Mon, 16 Jun 2025 17:01:14 +1000 Subject: [PATCH 3/3] 2.3.5 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9ce0bd437..675037e0e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "polykey", - "version": "2.3.4", + "version": "2.3.5", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "polykey", - "version": "2.3.4", + "version": "2.3.5", "license": "GPL-3.0", "dependencies": { "@matrixai/async-cancellable": "^2.0.1", diff --git a/package.json b/package.json index eafa990f3..6ff19843f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "polykey", - "version": "2.3.4", + "version": "2.3.5", "homepage": "https://polykey.com", "author": "Matrix AI", "contributors": [