From 52cbddf61639f12c8528c5a0384dcdba0c22593d Mon Sep 17 00:00:00 2001 From: Brian Botha Date: Fri, 6 Dec 2024 17:44:50 +1100 Subject: [PATCH 1/2] fix: cleaning up nodes tasks during startup that didn't clean up properly during ungraceful shutdown [ci skip] --- src/nodes/NodeManager.ts | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/nodes/NodeManager.ts b/src/nodes/NodeManager.ts index 6ab4b5b8e..8d7e72063 100644 --- a/src/nodes/NodeManager.ts +++ b/src/nodes/NodeManager.ts @@ -403,6 +403,8 @@ class NodeManager { this.syncNodeGraphHandlerId, this.syncNodeGraphHandler, ); + // This will clean up tasks that were not properly cleaned up during an ungracefully shutdown of the process + await this.stopTasks(); await this.setupRefreshBucketTasks(); // Can be disabled with 0 delay, only use for testing if (this.retryConnectionsDelayTime > 0) { @@ -445,15 +447,7 @@ class NodeManager { this.handleEventNodeConnectionManagerConnection, ); await this.mdns?.stop(); - // Cancels all NodeManager tasks - const taskPs: Array> = []; - for await (const task of this.taskManager.getTasks(undefined, false, [ - this.tasksPath, - ])) { - taskPs.push(task.promise()); - task.cancel(abortEphemeralTaskReason); - } - await Promise.allSettled(taskPs); + await this.stopTasks(); this.taskManager.deregisterHandler(this.refreshBucketHandlerId); this.taskManager.deregisterHandler(this.gcBucketHandlerId); this.taskManager.deregisterHandler(this.checkConnectionsHandlerId); @@ -2089,6 +2083,21 @@ class NodeManager { this.logger.info('Set up refreshBucket tasks'); } + /** + * Cancels all NodeManager tasks. + * These are ephemeral and will be recreated next time we start. + */ + protected async stopTasks() { + const taskPs: Array> = []; + for await (const task of this.taskManager.getTasks(undefined, false, [ + this.tasksPath, + ])) { + taskPs.push(task.promise()); + task.cancel(abortEphemeralTaskReason); + } + await Promise.allSettled(taskPs); + } + @ready(new nodesErrors.ErrorNodeManagerNotRunning(), true, ['stopping']) public async updateRefreshBucketDelay( bucketIndex: number, From 4e541c3005e15aef582a9c43e97e43e5efabb826 Mon Sep 17 00:00:00 2001 From: Brian Botha Date: Fri, 6 Dec 2024 17:45:01 +1100 Subject: [PATCH 2/2] 1.16.2 --- 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 3649a90c1..3bb9a0662 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "polykey", - "version": "1.16.1", + "version": "1.16.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "polykey", - "version": "1.16.1", + "version": "1.16.2", "license": "GPL-3.0", "dependencies": { "@matrixai/async-cancellable": "^1.1.1", diff --git a/package.json b/package.json index 998b13adc..0cc1c5329 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "polykey", - "version": "1.16.1", + "version": "1.16.2", "homepage": "https://polykey.com", "author": "Matrix AI", "contributors": [