Skip to content

Commit f72ba31

Browse files
committed
fix: fixed potential leak of setNode error
1 parent 171d473 commit f72ba31

File tree

1 file changed

+41
-30
lines changed

1 file changed

+41
-30
lines changed

src/nodes/NodeManager.ts

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ class NodeManager<Manifest extends AgentClientManifestNodeManager> {
310310
connectedTime: Date.now(),
311311
scopes: ['global'],
312312
},
313-
true,
313+
false,
314314
false,
315315
);
316316
};
@@ -925,7 +925,7 @@ class NodeManager<Manifest extends AgentClientManifestNodeManager> {
925925
});
926926
}
927927

928-
if (!connectionMade) {
928+
if (connectionMade == null) {
929929
throw new nodesErrors.ErrorNodeManagerFindNodeFailed(
930930
'failed to find node via direct',
931931
);
@@ -1312,8 +1312,8 @@ class NodeManager<Manifest extends AgentClientManifestNodeManager> {
13121312
@decorators.context ctx: ContextTimed,
13131313
): Promise<void> {
13141314
if (tran == null) {
1315-
return this.db.withTransactionF((tran) => {
1316-
return this.claimNode(targetNodeId, tran);
1315+
return await this.db.withTransactionF(async (tran) => {
1316+
return await this.claimNode(targetNodeId, tran);
13171317
});
13181318
}
13191319
const [, claim] = await this.sigchain.addClaim(
@@ -1515,8 +1515,9 @@ class NodeManager<Manifest extends AgentClientManifestNodeManager> {
15151515
tran?: DBTransaction,
15161516
): Promise<AgentRPCResponseResult<AgentClaimMessage>> {
15171517
if (tran == null) {
1518-
return this.db.withTransactionF((tran) =>
1519-
this.handleClaimNetwork(requestingNodeId, input, tran),
1518+
return await this.db.withTransactionF(
1519+
async (tran) =>
1520+
await this.handleClaimNetwork(requestingNodeId, input, tran),
15201521
);
15211522
}
15221523
const signedClaim = claimsUtils.parseSignedClaim(input.signedTokenEncoded);
@@ -1546,8 +1547,9 @@ class NodeManager<Manifest extends AgentClientManifestNodeManager> {
15461547
tran?: DBTransaction,
15471548
): Promise<AgentRPCResponseResult<{ success: true }>> {
15481549
if (tran == null) {
1549-
return this.db.withTransactionF((tran) =>
1550-
this.handleVerifyClaimNetwork(requestingNodeId, input, tran),
1550+
return await this.db.withTransactionF(
1551+
async (tran) =>
1552+
await this.handleVerifyClaimNetwork(requestingNodeId, input, tran),
15511553
);
15521554
}
15531555
const signedClaim = claimsUtils.parseSignedClaim(input.signedTokenEncoded);
@@ -1680,17 +1682,18 @@ class NodeManager<Manifest extends AgentClientManifestNodeManager> {
16801682
}
16811683

16821684
if (tran == null) {
1683-
return this.db.withTransactionF((tran) =>
1684-
this.setNode(
1685-
nodeId,
1686-
nodeAddress,
1687-
nodeContactAddressData,
1688-
block,
1689-
force,
1690-
connectionConnectTimeoutTime,
1691-
tran,
1692-
ctx,
1693-
),
1685+
return await this.db.withTransactionF(
1686+
async (tran) =>
1687+
await this.setNode(
1688+
nodeId,
1689+
nodeAddress,
1690+
nodeContactAddressData,
1691+
block,
1692+
force,
1693+
connectionConnectTimeoutTime,
1694+
tran,
1695+
ctx,
1696+
),
16941697
);
16951698
}
16961699

@@ -1824,13 +1827,14 @@ class NodeManager<Manifest extends AgentClientManifestNodeManager> {
18241827
tran?: DBTransaction,
18251828
): Promise<void> {
18261829
if (tran == null) {
1827-
return this.db.withTransactionF((tran) =>
1828-
this.garbageCollectBucket(
1829-
bucketIndex,
1830-
connectionConnectTimeoutTime,
1831-
ctx,
1832-
tran,
1833-
),
1830+
return await this.db.withTransactionF(
1831+
async (tran) =>
1832+
await this.garbageCollectBucket(
1833+
bucketIndex,
1834+
connectionConnectTimeoutTime,
1835+
ctx,
1836+
tran,
1837+
),
18341838
);
18351839
}
18361840

@@ -2041,8 +2045,8 @@ class NodeManager<Manifest extends AgentClientManifestNodeManager> {
20412045

20422046
protected async setupRefreshBucketTasks(tran?: DBTransaction) {
20432047
if (tran == null) {
2044-
return this.db.withTransactionF((tran) =>
2045-
this.setupRefreshBucketTasks(tran),
2048+
return await this.db.withTransactionF(
2049+
async (tran) => await this.setupRefreshBucketTasks(tran),
20462050
);
20472051
}
20482052

@@ -2149,8 +2153,15 @@ class NodeManager<Manifest extends AgentClientManifestNodeManager> {
21492153
@decorators.context ctx: ContextTimed,
21502154
): Promise<Task> {
21512155
if (tran == null) {
2152-
return this.db.withTransactionF((tran) =>
2153-
this.updateRefreshBucketDelay(bucketIndex, delay, lazy, tran, ctx),
2156+
return await this.db.withTransactionF(
2157+
async (tran) =>
2158+
await this.updateRefreshBucketDelay(
2159+
bucketIndex,
2160+
delay,
2161+
lazy,
2162+
tran,
2163+
ctx,
2164+
),
21542165
);
21552166
}
21562167

0 commit comments

Comments
 (0)