Skip to content

Comments

PSMDB-1959 Fix stacktrace tests broken by dev_stacktrace enabled by default#1692

Merged
igorsol merged 1 commit intomasterfrom
psmdb-1959
Feb 20, 2026
Merged

PSMDB-1959 Fix stacktrace tests broken by dev_stacktrace enabled by default#1692
igorsol merged 1 commit intomasterfrom
psmdb-1959

Conversation

@igorsol
Copy link

@igorsol igorsol commented Feb 19, 2026

When MONGO_CONFIG_DEV_STACKTRACE is defined, printStackTrace() routes to printCppTrace() (cpptrace format) instead of the structured JSON output. Tests that expect structured JSON format were broken.

Fix by calling printStructuredStackTrace(StackTraceSink&) directly, bypassing the dev_stacktrace routing, in the three affected call sites:

  • stacktrace_libunwind_test_functions.cpp: staticFunction (Linkage test)
  • stacktrace_test.cpp: PosixFormat test lambda
  • stacktrace_test.cpp: traceString() (EarlyTraceSanity test)

…efault

When MONGO_CONFIG_DEV_STACKTRACE is defined, printStackTrace() routes
to printCppTrace() (cpptrace format) instead of the structured JSON
output. Tests that expect structured JSON format were broken.

Fix by calling printStructuredStackTrace(StackTraceSink&) directly,
bypassing the dev_stacktrace routing, in the three affected call sites:
- stacktrace_libunwind_test_functions.cpp: staticFunction (Linkage test)
- stacktrace_test.cpp: PosixFormat test lambda
- stacktrace_test.cpp: traceString() (EarlyTraceSanity test)
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes stacktrace tests that broke when MONGO_CONFIG_DEV_STACKTRACE was enabled by default. When this config is defined and enabled, printStackTrace() routes to printCppTrace() (cpptrace format) instead of structured JSON output. Tests expecting structured JSON format were failing. The fix ensures these tests call printStructuredStackTrace() directly, bypassing the dev_stacktrace routing.

Changes:

  • Modified three test call sites to use printStructuredStackTrace(sink) instead of printStackTrace() to ensure structured JSON output regardless of dev_stacktrace configuration
  • Added explicit OstreamStackTraceSink creation where previously printStackTrace(os) was called directly with an ostream

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/mongo/util/stacktrace_test.cpp Fixed PosixFormat test lambda (line 180) and traceString() helper (lines 306-307) to call printStructuredStackTrace() directly with explicit sink creation
src/mongo/util/stacktrace_libunwind_test_functions.cpp Fixed staticFunction() used by Linkage test (lines 44-45) to call printStructuredStackTrace() with explicit sink creation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +306 to +307
OstreamStackTraceSink sink{os};
printStructuredStackTrace(sink);
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix correctly bypasses the dev_stacktrace routing by calling printStructuredStackTrace(sink) directly. However, there's an underlying issue in the stacktrace implementation itself: In stacktrace_posix.cpp (line 491) and stacktrace_windows.cpp (line 334), the printStructuredStackTrace(std::ostream& os) overload creates an OstreamStackTraceSink and then calls printStackTrace(sink) instead of printStructuredStackTrace(sink). This defeats the purpose of having a separate printStructuredStackTrace function, as it will still route through the dev_stacktrace logic when MONGO_CONFIG_DEV_STACKTRACE is defined. Those implementations should call printStructuredStackTrace(sink) to be consistent with the intent.

Copilot uses AI. Check for mistakes.
Copy link
Author

@igorsol igorsol Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that is a correct point, however it is out of the context, it requires additional investigation because we don't know why it was implemented this way by MongoDB developers (was it intended when --dev_stacktrace was introduced?).

@igorsol igorsol requested review from ktrushin and plebioda February 19, 2026 19:18
Copy link

@ktrushin ktrushin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@igorsol igorsol merged commit cd0ebab into master Feb 20, 2026
11 checks passed
@igorsol igorsol deleted the psmdb-1959 branch February 20, 2026 11:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants