fix: prevent "sonic boom is not ready yet" errors on system settings change

This commit is contained in:
Christian Benincasa
2026-01-20 10:36:43 -05:00
parent f6f9c8accf
commit ca8e393e4f
3 changed files with 14 additions and 4 deletions

View File

@@ -196,10 +196,6 @@ export const systemApiRouter: RouterPluginAsyncCallback = async (
return file;
});
if (req.body.logging?.logRollConfig) {
LoggerFactory.rollLogsNow();
}
const refreshedSettings = req.serverCtx.settings.systemSettings();
return res.send(getSystemSettingsResponse(refreshedSettings));

View File

@@ -133,6 +133,9 @@ class LoggerFactoryImpl {
!isEqual(prevSettings.system.logging.logRollConfig, currentSettings)
) {
this.updateLevel(newLevel);
setTimeout(() => {
this.rollLogsNow();
});
}
});

View File

@@ -41,6 +41,7 @@ export class RollingLogDestination {
private currentFileName: string;
private createdFileNames: string[] = [];
private rotatePattern: RegExp;
private destinationReady = false;
constructor(private opts: Opts) {
this.rotatePattern = new RegExp(`(\\d+)${this.opts.extension ?? ''}$`);
@@ -76,6 +77,10 @@ export class RollingLogDestination {
dest: this.opts.fileName,
});
this.destination.once('ready', () => {
this.destinationReady = true;
});
if (this.opts.maxSizeBytes && this.opts.maxSizeBytes > 0) {
let currentSize = getFileSize(this.currentFileName);
this.destination.on('write', (size) => {
@@ -111,12 +116,18 @@ export class RollingLogDestination {
return;
}
this.destinationReady = false;
this.destination.end();
this.scheduledTask?.cancel(false);
}
roll() {
if (!this.destination) {
return;
} else if (!this.destinationReady) {
this.destination.once('ready', () => this.roll());
return;
}
this.destination.flushSync();