Repository navigation
Conversation
InitializeStackFromSP bounds a thread's stack capture with the thread pointer, which is a big improvement on capturing the whole mapping. On glibc, though, the static TLS block sits immediately below the thread pointer, at the high-address end of the same mapping, so every thread is still captured as its live stack plus that entire block. The block scales with the number of loaded DSOs, not with anything about the thread. On one real application it is ~175 KB per thread, of which around 700 bytes is live stack - glog's thread_local LogMessageData alone contributes 30,448 bytes, and CUDA's runtime and NPP libraries several kilobytes each. Byte-parsing a 144.9 MB minidump from that application: 143.8 MB, 99.2% of the file, was thread stacks across 818 threads, and almost all of it zeroes. Cap the captured length. The region starts at the stack pointer and grows towards the stack base, so shortening it drops the TLS block before it drops any frame; the deepest live non-main stack measured across four applications was 12.4 KB, against a 64 KB cap. The main thread already keeps its full stack via the enclosing tid check. Measured effect: 144.9 MB -> 54.0 MB, and 37.5 MB -> 12.4 MB on a second application. Backtraces are unaffected - a capped thread still walks from the faulting frame to thread entry.
fran6co
force-pushed
the
fran6co/cap-stack-capture
branch
from
July 31, 2026 15:38
f3026a1 to
80ae102
Compare
| // Truncating the length drops the static TLS block, which sits at the | ||
| // stack base end of the region, rather than any frame. | ||
| constexpr LinuxVMSize kMaxCapturedStackSize = 64 * 1024; | ||
| stack_region_size = std::min(stack_region_size, kMaxCapturedStackSize); |
There was a problem hiding this comment.
Bug: The 64 KB stack cap applied to non-main threads can truncate the stack trace of a crashing thread, potentially hiding the root cause of the crash.
Severity: HIGH
Suggested Fix
The 64 KB stack cap should not be applied to the specific thread that is crashing. The logic should be modified to check if the thread being processed is the one that triggered the exception and, if so, bypass the stack truncation to ensure the full stack trace is always captured for crash analysis.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: snapshot/linux/process_reader_linux.cc#L211
Potential issue: When a non-main thread crashes, its stack is captured for the minidump.
The logic at `process_reader_linux.cc:211` unconditionally caps this captured stack at
64 KB for all non-main threads. If a crashing thread's call stack is deeper than 64 KB,
which can occur with recursion or complex library calls, the stack trace will be
truncated. This results in an incomplete crash report that may be missing the crucial
frames needed to diagnose the root cause of the crash, severely hindering debugging
efforts.
Did we get this right? 👍 / 👎 to inform future reviews.
Author
|
This is not a good fix as pointed out by the review |
This was referenced Sep 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ProcessReaderLinux::Thread::InitializeStackFromSPbounds a thread's stack capture with the thread pointer, which is a big improvement on capturing the whole mapping. On glibc, though, the static TLS block sits immediately below the thread pointer, at the high-address end of that same mapping — so every thread is captured aslive stack + the entire static TLS block.The block scales with the number of loaded DSOs, not with anything about the thread.
I byte-parsed a 144.9 MB minidump from a production application:
Per thread that is ~175 KB, of which around 700 bytes was live stack — the rest zeroes. The contributors are ordinary libraries:
libglog'sthread_local LogMessageDatais 30,448 B on its own (it holds a 30,001-byte message buffer), plus ~4 KB each fromlibcudartand eightlibnpp*. The intra-application spread was ±3%, which is the signature of a fixed per-thread constant rather than of stack usage.Fix
Cap the captured length for non-main threads. The region starts at the stack pointer and grows towards the stack base, so shortening it discards the TLS block before it discards any frame. The main thread already keeps its full stack via the enclosing
tid != reader->ProcessID()check.Why 64 KB is safe
The deepest live non-main stack I measured across four applications was 12.4 KB, so the cap has ~5x headroom. Verified that a capped thread still walks correctly end to end —
minidump-stackwalkon a dump whose crashing thread was capped (65,536 B kept of a 113,072 B span):Measured effect
Beyond file size this matters for how long a dump takes to write, which is load-bearing when the client is waiting on it.
🤖 Generated with Claude Code