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": [ 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,