fix(protocol): stop flooding logs when disk writes fail
After identity persistence is suspended, later observations were still logged one-by-one. That filled Docker logs and made the WebUI log stream unusable while the bot kept receiving messages. Report the skip once, then at most once a minute with a count. Console write failures must not throw into message handling.
This commit is contained in:
5 files changed
+64
-4
No files matched your search
@@ -506,7 +506,13 @@ class FileWriter {
|
||||
}
|
||||
|
||||
if (!this.quota.reserve(this.file.path, bytes)) return false;
|
||||
this.file.stream.write(data);
|
||||
try {
|
||||
this.file.stream.write(data);
|
||||
} catch (error) {
|
||||
this.disabled = true;
|
||||
this.quota.writeFailed(this.file.path, error);
|
||||
return false;
|
||||
}
|
||||
this.file.bytes += bytes;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -264,7 +264,13 @@ function emit(
|
||||
// and ESC (0x1B) so multi-line records (stack traces) and ANSI color
|
||||
// sequences emitted by render() pass through intact.
|
||||
// eslint-disable-next-line no-control-regex
|
||||
stream.write(line.replace(/[\x00-\x08\x0B-\x1A\x1C-\x1F\x7F]/g, '') + '\n');
|
||||
const consoleLine = line.replace(/[\x00-\x08\x0B-\x1A\x1C-\x1F\x7F]/g, '') + '\n';
|
||||
try {
|
||||
stream.write(consoleLine);
|
||||
} catch {
|
||||
// A full Docker json-file log volume can make stdout/stderr throw.
|
||||
// Logging must not take down message handling or the WebUI.
|
||||
}
|
||||
}
|
||||
|
||||
// File transport sees levels >= currentFileLevel (SNOWLUMA_LOG_FILE_LEVEL,
|
||||
|
||||
@@ -60,6 +60,13 @@ describe('logger UIN slot padding', () => {
|
||||
expect(() => createLogger('Test').info('no uin')).not.toThrow();
|
||||
});
|
||||
|
||||
it('does not throw when the console stream cannot accept the line', () => {
|
||||
vi.mocked(process.stderr.write).mockImplementation(() => {
|
||||
throw Object.assign(new Error('ENOSPC: no space left on device'), { code: 'ENOSPC' });
|
||||
});
|
||||
expect(() => createLogger('Test').error('disk is full')).not.toThrow();
|
||||
});
|
||||
|
||||
it('keeps structured subscriber lines plain while terminal output stays colored', () => {
|
||||
const captured: LogEntry[] = [];
|
||||
const unsubscribe = subscribeLogs((entry) => captured.push(entry));
|
||||
|
||||
Reference in new issue
Block a user