From 5ceb57e54017bc31ccbcf9bbc1729ac1e3ad1ac8 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Mon, 10 May 2021 01:03:04 -0400 Subject: [PATCH] Handle emptying corrupted console log files Libvirt will someones write junk out to console log files, which breaks the log parser deque with a UnicodeDecodeError. If this happens, clear the log and re-open the deque again for newer updates. Closes #123 --- node-daemon/pvcnoded/VMConsoleWatcherInstance.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/node-daemon/pvcnoded/VMConsoleWatcherInstance.py b/node-daemon/pvcnoded/VMConsoleWatcherInstance.py index 2d27f3b1..9561c678 100644 --- a/node-daemon/pvcnoded/VMConsoleWatcherInstance.py +++ b/node-daemon/pvcnoded/VMConsoleWatcherInstance.py @@ -44,7 +44,14 @@ class VMConsoleWatcherInstance(object): open(self.logfile, 'a').close() os.chmod(self.logfile, 0o600) - self.logdeque = deque(open(self.logfile), self.console_log_lines) + try: + self.logdeque = deque(open(self.logfile), self.console_log_lines) + except UnicodeDecodeError: + # There is corruption in the log file; overwrite it + self.logger.out('Failed to decode console log file; clearing existing file', state='w', prefix='Domain {}'.format(self.domuuid)) + with open(self.logfile, 'w') as lfh: + lfh.write('\n') + self.logdeque = deque(open(self.logfile), self.console_log_lines) self.stamp = None self.cached_stamp = None