Skip to content

Commit

Permalink
Check for rr traceback in stderr logs and display warning
Browse files Browse the repository at this point in the history
  • Loading branch information
tysmith committed May 17, 2024
1 parent 6bb27b7 commit 86488ec
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/ffpuppet/puppet_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""browser and debugger log management"""

from logging import getLogger
from mmap import ACCESS_READ, mmap
from os import getpid, stat
from os.path import isfile
from pathlib import Path
Expand Down Expand Up @@ -268,6 +269,16 @@ def save_logs(
if not logs_only:
rr_trace = self.path / self.PATH_RR / "latest-trace"
if rr_trace.is_dir():
# check logs for rr related issues
try:
with (dest / "log_stderr.txt").open("rb") as lfp:
with mmap(lfp.fileno(), 0, access=ACCESS_READ) as lmm:
if lmm.find(b"=== Start rr backtrace:") != -1:
LOG.warning("rr traceback detected in stderr log")
except (OSError, ValueError): # pragma: no cover
# OSError: in case the file does not exist
# ValueError: cannot mmap an empty file on Windows
pass
if rr_pack and not self._rr_packed:
LOG.debug("packing rr trace")
try:
Expand Down
6 changes: 6 additions & 0 deletions src/ffpuppet/test_puppet_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ def test_puppet_logger_07(mocker, tmp_path):
fake_ck = mocker.patch("ffpuppet.puppet_logger.check_output", autospec=True)
with PuppetLogger(base_path=str(tmp_path)) as plog:
assert plog.path is not None
# add log data to test rr backtrace detection
with (tmp_path / "test_stderr.txt").open("w+b") as in_fp:
in_fp.write(b"foo\n")
in_fp.write(b"=== Start rr backtrace:\n")
in_fp.write(b"foo\n")
plog.add_log("stderr", logfp=in_fp)
(plog.path / plog.PATH_RR / "latest-trace").mkdir(parents=True)
plog.close()
# test call to rr failing
Expand Down

0 comments on commit 86488ec

Please sign in to comment.