fix: preserve active system log files when clearing logs

This commit is contained in:
whyour
2026-10-17 07:42:10 +08:00
parent ef348b445b
commit 1a152575cc
2 changed files with 81 additions and 1 deletions
+11 -1
View File
@@ -606,7 +606,17 @@ export default class SystemService {
const result = await readDirs(config.systemLogPath, config.systemLogPath);
const logs = result.reverse().filter((x) => x.title.endsWith('.log'));
for (const log of logs) {
await rmPath(path.join(config.systemLogPath, log.title));
// All workers keep append handles open; unlinking strands future writes
// in a deleted inode until rotation. Preserve the file while clearing it.
const file = await fs.promises.open(
path.join(config.systemLogPath, log.title),
fs.constants.O_WRONLY | fs.constants.O_NOFOLLOW,
);
try {
await file.truncate(0);
} finally {
await file.close();
}
}
}