Skip to content

Commit

Permalink
fix: cleaning up nodes tasks during startup that didn't clean up prop…
Browse files Browse the repository at this point in the history
…erly during ungraceful shutdown

[ci skip]
  • Loading branch information
tegefaulkes committed Dec 6, 2024
1 parent ee88b9c commit 52cbddf
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/nodes/NodeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -445,15 +447,7 @@ class NodeManager {
this.handleEventNodeConnectionManagerConnection,
);
await this.mdns?.stop();
// Cancels all NodeManager tasks
const taskPs: Array<Promise<any>> = [];
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);
Expand Down Expand Up @@ -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<Promise<any>> = [];
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,
Expand Down

0 comments on commit 52cbddf

Please sign in to comment.