Skip to content

tests: stop crash-log assertions failing on non-UTF-8 log bytes - #10910

Merged
kei-nan merged 1 commit into
masterfrom
jk-crash-log-utf8
Aug 13, 2026
Merged

kei-nan merged 1 commit into
masterfrom
jk-crash-log-utf8

Conversation

@kei-nan

@kei-nan kei-nan commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

Describe the changes in the pull request

  1. Current: test_crash.py and test_tracing.py read the server log file with
    open(path) — the default strict UTF-8 decode. A crash report, and any log line
    interleaved with it while the crash handler runs, can contain raw memory bytes, so
    the log is not guaranteed to be valid UTF-8. A single invalid byte anywhere in the
    file aborts the read, and the test errors out before it can assert anything:

    UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb8 in position 3286: invalid start byte
      test_crash.py, line 81, in test_query_thread_crash
      test_crash.py, line 49, in extract_query_crash_output  ->  for line in logFile:
    

    This was hit in CI by test_crash:test_query_thread_crash, where a background thread
    logged the raw bytes of a pointer while the crash handler was running its memory test:

    *** Preparing to test memory region ffe4933ac000 (8192 bytes)
    .O.O.O.O.O.O.O.O.O.# Compress error -2: \xb8\x9b6\x92\xe4\xff
    

    The failure has nothing to do with the fragments the test is looking for — those were
    all present and correct in that same log.

  2. Change: read the log with encoding="utf-8", errors="replace" at both call sites.
    Both only match ASCII fragments, so a lossy decode cannot change what they find.
    Pinning the encoding also stops the decode depending on the runner's locale.

  3. Outcome: the crash tests assert on the crash report's contents instead of failing
    on unrelated bytes elsewhere in the log. Replaying extract_query_crash_output's
    parser over the log that failed in CI now finds all eight expected fragments in order
    and satisfies every assertion in test_query_thread_crash
    (search_number_of_docs: 10, max_doc_id=10, num_terms=2, inverted_size > 0).

Which additional issues this PR fixes

  1. None.

Main objects this PR modified

  1. tests/pytests/test_crash.py — extract_query_crash_output()
  2. tests/pytests/test_tracing.py — _log_has_init_message()

Mark if applicable

  • This PR introduces API changes
  • This PR introduces serialization changes

Release Notes

  • This PR requires release notes
  • This PR does not require release notes

A crash report, and the log lines interleaved with it while the crash
handler runs, can contain raw memory bytes. `test_crash` and
`test_tracing` read the server log with the default strict UTF-8 decode,
so a single invalid byte anywhere in the file raises UnicodeDecodeError
and errors the test out before it can check anything:

    UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb8 in position
    3286: invalid start byte

Both only match ASCII fragments, so decode lossily and pin the encoding
rather than inheriting it from the locale.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@kei-nan
kei-nan requested a review from GuyAv46 August 13, 2026 12:45
@kei-nan kei-nan self-assigned this Aug 13, 2026
@kei-nan
kei-nan enabled auto-merge August 13, 2026 12:46
@codecov

codecov Bot commented Aug 13, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.21%. Comparing base (1fec8e2) to head (d50aac1).

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #10910      +/-   ##
==========================================
- Coverage   83.19%   82.21%   -0.98%     
==========================================
  Files         608      632      +24     
  Lines       81025    82134    +1109     
  Branches    36273    37382    +1109     
==========================================
+ Hits        67405    67529     +124     
- Misses      13274    14259     +985     
  Partials      346      346              
Flag Coverage Δ
flow 84.34% <ø> (-0.04%) ⬇️
unit 55.73% <ø> (-0.60%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sonarqubecloud

Copy link
Copy Markdown

@kei-nan
kei-nan added this pull request to the merge queue Aug 13, 2026
Merged via the queue into master with commit 71aeb0a Aug 13, 2026
58 checks passed
@kei-nan
kei-nan deleted the jk-crash-log-utf8 branch August 13, 2026 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants