Skip to content

Commit 434cbec

Browse files
committed
Fix decoding error when reading server's log file
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.
1 parent 52ca8cf commit 434cbec

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

lib/tarantool_server.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
from lib.utils import warn_unix_socket
4646
from lib.utils import prefix_each_line
4747
from lib.utils import prepend_path
48+
from lib.utils import PY3
4849
from lib.test import TestRunGreenlet, TestExecutionError
4950

5051

@@ -440,17 +441,27 @@ def __init__(self, path):
440441
self.path = path
441442
self.log_begin = 0
442443

444+
def open(self, mode, **kwargs):
445+
if PY3:
446+
# Sometimes the server's log file may contain bytes that cannot be
447+
# decoded by utf-8 codec and test-run fails with an error like this:
448+
# UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf0 in
449+
# position 660: invalid continuation byte
450+
# The option below fixes it. Note, Python2 doesn't know the option.
451+
kwargs['errors'] = 'replace'
452+
return open(self.path, mode, **kwargs)
453+
443454
def positioning(self):
444455
if os.path.exists(self.path):
445-
with open(self.path, 'r') as f:
456+
with self.open('r') as f:
446457
f.seek(0, os.SEEK_END)
447458
self.log_begin = f.tell()
448459
return self
449460

450461
def seek_once(self, msg):
451462
if not os.path.exists(self.path):
452463
return -1
453-
with open(self.path, 'r') as f:
464+
with self.open('r') as f:
454465
f.seek(self.log_begin, os.SEEK_SET)
455466
while True:
456467
log_str = f.readline()
@@ -472,7 +483,7 @@ def seek_wait(self, msg, proc=None, name=None, deadline=None):
472483
"seconds\n".format(self.path, timeout), schema='error')
473484
return False
474485

475-
with open(self.path, 'r') as f:
486+
with self.open('r') as f:
476487
f.seek(self.log_begin, os.SEEK_SET)
477488
cur_pos = self.log_begin
478489
while not deadline or time.time() < deadline:
@@ -979,7 +990,7 @@ def crash_grep(self):
979990
# find and save backtrace or assertion fail
980991
assert_lines = list()
981992
bt = list()
982-
with open(self.logfile, 'r') as log:
993+
with self.logfile_pos.open('r') as log:
983994
lines = log.readlines()
984995
for rpos, line in enumerate(reversed(lines)):
985996
if line.startswith('Segmentation fault'):

0 commit comments

Comments
 (0)