AP_HAL_SITL: do not truncate the stack dump on a short write - #34077
Open
peterbarker wants to merge 1 commit into
Open
AP_HAL_SITL: do not truncate the stack dump on a short write#34077peterbarker wants to merge 1 commit into
peterbarker wants to merge 1 commit into
Conversation
dump_stack_trace() and dump_core_file() both run a script on our own pid
and copy its output to stderr a block at a time. The copy ended on any
write() which did not place the whole block:
if (write(2, buf, ret) != ret) {
// *sigh*
break;
}
write() is entitled to do that. stderr is a pipe when SITL runs under
autotest, so a full pipe shortens a write, and a timer signal can cut one
short with EINTR. Either way the copy stopped silently, part-way
through, with no "end dumpstack.sh output" line to show that anything was
missing.
Seen in CI: a backtrace ended at frame #8, in the middle of the frame
which would have named the caller - the one thing the dump exists to
provide. A truncated core dump goes the same way and is even easier to
miss.
Keep writing until the block is out, retry EINTR on both the read and the
write, and say so if a write really does fail.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Summary
Overlook short writes when taking stack traces (system is perfectly entitled to do that)
Classification & Testing (check all that apply and add your own)
Description
dump_stack_trace() and dump_core_file() both run a script on our own pid and copy its output to stderr a block at a time. The copy ended on any write() which did not place the whole block:
write() is entitled to do that. stderr is a pipe when SITL runs under autotest, so a full pipe shortens a write, and a timer signal can cut one short with EINTR. Either way the copy stopped silently, part-way through, with no "end dumpstack.sh output" line to show that anything was missing.
Seen in CI: a backtrace ended at frame #8, in the middle of the frame which would have named the caller - the one thing the dump exists to provide. A truncated core dump goes the same way and is even easier to miss.
Keep writing until the block is out, retry EINTR on both the read and the write, and say so if a write really does fail.