fix(cluster): skip persistence scheduling until initialize has run
schedulePersist and scheduleControlPersist can fire from configure() and the public scheduling paths before initialize() has completed. Without a guard, those queued microtasks call persistState/persistControlState, which try to mkdir PATHS.DATA_DIR and write state files from tests and short-lived scripts that never meant to touch the data directory. That produced async-leak warnings in the Cluster manager unit tests and left orphan directories on hosts that only constructed a ClusterManager to inspect it. Add an `initialized` flag set at the end of initialize() and early-return from both schedulers when it is false. Real runtime paths always call initialize() during Daemon startup, so this changes no production behavior.
This commit is contained in:
@@ -13,6 +13,7 @@ import type {
|
|||||||
import { CLUSTER, PATHS } from '../constants.ts';
|
import { CLUSTER, PATHS } from '../constants.ts';
|
||||||
|
|
||||||
export class ClusterManager {
|
export class ClusterManager {
|
||||||
|
private initialized = false;
|
||||||
private config: IClusterConfig = {
|
private config: IClusterConfig = {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
nodeName: 'modelgrid-local',
|
nodeName: 'modelgrid-local',
|
||||||
@@ -63,6 +64,8 @@ export class ClusterManager {
|
|||||||
} catch {
|
} catch {
|
||||||
// No persisted control state yet.
|
// No persisted control state yet.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public configure(config: IClusterConfig): void {
|
public configure(config: IClusterConfig): void {
|
||||||
@@ -384,6 +387,10 @@ export class ClusterManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private schedulePersist(): void {
|
private schedulePersist(): void {
|
||||||
|
if (!this.initialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.persistQueued) {
|
if (this.persistQueued) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -396,6 +403,10 @@ export class ClusterManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private scheduleControlPersist(): void {
|
private scheduleControlPersist(): void {
|
||||||
|
if (!this.initialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.controlPersistQueued) {
|
if (this.controlPersistQueued) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user