Skip to content

Commit

Permalink
Fix decoding error when reading server's log file
Browse files Browse the repository at this point in the history
When a diff test starts a Tarantool server, test-run reads the server's
log file and tries to find the message indicating the server is ready.
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:

    [044] TarantoolInpector.handle() received the following error:
    [044] Traceback (most recent call last):
    [044]   File "/tarantool/test-run/lib/inspector.py", line 98, in handle
    [044]     result = self.parser.parse_preprocessor(line)
    [044]   File "/tarantool/test-run/lib/preprocessor.py", line 123, in parse_preprocessor
    [044]     return self.server(stype, sname, options)
    [044]   File "/tarantool/test-run/lib/preprocessor.py", line 351, in server
    [044]     return getattr(self, attr)(ctype, sname, opts)
    [044]   File "/tarantool/test-run/lib/preprocessor.py", line 209, in server_start
    [044]     self.servers[sname].start(silent=True, rais=True, wait=wait,
    [044]   File "/tarantool/test-run/lib/tarantool_server.py", line 910, in start
    [044]     self.wait_until_started(wait_load, deadline)
    [044]   File "/tarantool/test-run/lib/tarantool_server.py", line 1147, in wait_until_started
    [044]     self.wait_load(deadline)
    [044]   File "/tarantool/test-run/lib/tarantool_server.py", line 1131, in wait_load
    [044]     if not self.logfile_pos.seek_wait(msg, p, self.name, deadline):
    [044]   File "/tarantool/test-run/lib/tarantool_server.py", line 485, in seek_wait
    [044]     log_str = f.readline()
    [044]   File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/codecs.py", line 322, in decode
    [044]     (result, consumed) = self._buffer_decode(data, self.errors, final)
    [044] UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf0 in position 660: invalid continuation byte

At least, I have seen such errors when Tarantool with JIT enabled was
tested on macOS ARM64 machines. So this patch fixes the issue.
  • Loading branch information
ylobankov committed Feb 13, 2024
1 parent 52ca8cf commit 434cbec
Showing 1 changed file with 15 additions and 4 deletions.
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

0 comments on commit 434cbec

Please sign in to comment.