Skip to content

Commit 53ac21e

Browse files
groeneaiclaude
andcommitted
ci: tail-read hung_check.log instead of loading the full file
Address the bot review on #103551: > Reading the whole `hung_check.log` here can allocate a lot of memory > exactly on deadlock cases, where this file may be very large (full > processlist + multiple `gdb` backtraces). Since we only need the last > 32 KiB, please read just the tail (seek from end and decode that > chunk) instead of `read_text` on the full file. The previous version called `Path.read_text` which loads the entire file into memory. On a real stress-test deadlock the log can grow into the tens or hundreds of MiB once the processlist of every hung query and the `gdb` backtrace of every server process are included, and the machine is already under memory pressure. Switch to a bounded tail read: open in binary mode, `seek` to `max(0, size - 32 KiB)`, read the remaining bytes, decode with `errors="replace"`. When the file did not fit in the budget, drop the likely-partial first line so the tail always starts on a line boundary, then prepend the existing truncation header. Successful parsing of the resulting `test_results.tsv` row was verified end-to- end against the same decoder used by `process_results` (tab/newline escape round-trip), for empty / 1 KiB / 30 KiB / 40 KiB / 250 KiB / 5 MiB synthetic logs. Behavior on the success branch and the small-file path is unchanged; only the resource profile of the failure path is improved. Session: cron:clickhouse-ci-task-worker:20260426-161500 Co-Authored-By: Claude Opus 4.7 <[email protected]>
1 parent c445d07 commit 53ac21e

1 file changed

Lines changed: 26 additions & 10 deletions

File tree

‎ci/jobs/scripts/stress/stress.py‎

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -647,19 +647,35 @@ def main():
647647
# are visible in CIDB. The full log is also kept as a CI
648648
# artifact (see process_results in stress_job.py), giving
649649
# investigators access to the complete diagnostic output.
650+
#
651+
# Read only the last 32 KiB rather than the whole file: on
652+
# deadlock failures `hung_check.log` can be very large (a
653+
# full processlist plus a `gdb` backtrace for every server
654+
# process), and the stress-test machine is already under
655+
# memory pressure. The diagnostic content we need
656+
# (`Found hung queries`, the processlist with stacktraces,
657+
# the `gdb` backtraces) is printed at the end of the log,
658+
# so the tail is exactly the relevant region.
650659
info_field = ""
651660
try:
652-
log_text = hung_check_log.read_text(errors="replace")
653-
# 32 KiB is enough for the processlist and a handful of
654-
# stacktraces. Keep the tail because the diagnostic
655-
# content (Found hung queries, processlist with
656-
# stacktraces, gdb backtraces) appears at the end.
657-
max_chars = 32 * 1024
658-
if len(log_text) > max_chars:
661+
tail_bytes_size = 32 * 1024
662+
with open(hung_check_log, "rb") as f:
663+
f.seek(0, os.SEEK_END)
664+
size = f.tell()
665+
offset = max(0, size - tail_bytes_size)
666+
f.seek(offset)
667+
tail_bytes = f.read()
668+
log_text = tail_bytes.decode("utf-8", errors="replace")
669+
if offset > 0:
670+
# Drop the (likely partial) first line so the tail
671+
# always starts on a line boundary.
672+
nl = log_text.find("\n")
673+
if nl >= 0:
674+
log_text = log_text[nl + 1 :]
659675
log_text = (
660-
"(truncated; see hung_check.log artifact for the"
661-
" full output; showing last 32 KiB)\n...\n"
662-
+ log_text[-max_chars:]
676+
"(truncated; see hung_check.log artifact for"
677+
" the full output; showing last 32 KiB)\n...\n"
678+
+ log_text
663679
)
664680
# Escape so tab and newline survive the TSV encoding,
665681
# matching the decoder in read_test_results().

0 commit comments

Comments
 (0)