Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix decoding error when reading server log file #422

Merged
merged 1 commit into from Feb 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 15 additions & 4 deletions lib/tarantool_server.py
Expand Up @@ -45,6 +45,7 @@
from lib.utils import warn_unix_socket
from lib.utils import prefix_each_line
from lib.utils import prepend_path
from lib.utils import PY3
from lib.test import TestRunGreenlet, TestExecutionError


Expand Down Expand Up @@ -440,17 +441,27 @@ def __init__(self, path):
self.path = path
self.log_begin = 0

def open(self, mode, **kwargs):
if PY3:
# Sometimes the server's log file may contain bytes that cannot be
# decoded by utf-8 codec and test-run fails with an error like this:
# UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf0 in
# position 660: invalid continuation byte
# The option below fixes it. Note, Python2 doesn't know the option.
kwargs['errors'] = 'replace'
return open(self.path, mode, **kwargs)

def positioning(self):
if os.path.exists(self.path):
with open(self.path, 'r') as f:
with self.open('r') as f:
f.seek(0, os.SEEK_END)
self.log_begin = f.tell()
return self

def seek_once(self, msg):
if not os.path.exists(self.path):
return -1
with open(self.path, 'r') as f:
with self.open('r') as f:
f.seek(self.log_begin, os.SEEK_SET)
while True:
log_str = f.readline()
Expand All @@ -472,7 +483,7 @@ def seek_wait(self, msg, proc=None, name=None, deadline=None):
"seconds\n".format(self.path, timeout), schema='error')
return False

with open(self.path, 'r') as f:
with self.open('r') as f:
f.seek(self.log_begin, os.SEEK_SET)
cur_pos = self.log_begin
while not deadline or time.time() < deadline:
Expand Down Expand Up @@ -979,7 +990,7 @@ def crash_grep(self):
# find and save backtrace or assertion fail
assert_lines = list()
bt = list()
with open(self.logfile, 'r') as log:
with self.logfile_pos.open('r') as log:
lines = log.readlines()
for rpos, line in enumerate(reversed(lines)):
if line.startswith('Segmentation fault'):
Expand Down