Skip to content

Fix out-of-bounds read in repeated bthread span tests - #3760

Merged
chenBright merged 1 commit into
apache:masterfrom
chenBright:fix-span-ut
Nov 19, 2026
Merged

chenBright merged 1 commit into
apache:masterfrom
chenBright:fix-span-ut

Conversation

@chenBright

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: resolve

Problem Summary:

BthreadTest.test_span uses a static counter to index a four-element array of span IDs. The first run consumes all four entries. When Google Test repeats the test in the same process, the first span created on the second run reads past the end of the array.

What is changed and the side effects?

Changed:

  • Replace the static counter and ID array with a span tree local to each test run.
  • Check that each child and grandchild receives its expected span, regardless of which branch runs first.
  • Restore the original span callbacks and the calling thread's parent span when the test exits, including after a failed assertion.

Side effects:

  • Performance effects:

  • Breaking backward compatibility:


Check List:

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain, and the test now isolates per-run span state while restoring span configuration during cleanup.

No open issues 🎉

What changed in this PR

This PR fixes repeated execution of BthreadTest.test_span by replacing process-wide span state with per-test span objects and restoring span configuration on exit.

Changes:

  • Replaces the static span counter and fixed ID array with a local span tree.
  • Validates parent and nested span inheritance across scheduling orders.
  • Restores span callbacks and the calling thread’s parent span with a scope guard.
File Description
test/​bthread_unittest.cpp Refactors the span propagation test to use isolated per-run span state, validate nested inheritance, and restore span configuration during cleanup.

Review effort: Lite

@chenBright chenBright added the status/ready-to-merge Required approvals and checks are satisfied, with no blocking feedback remaining label Nov 19, 2026
@chenBright
chenBright requested review from wasphin and wwbmmm November 19, 2026 03:15

@wasphin wasphin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@chenBright
chenBright merged commit f09379c into apache:master Nov 19, 2026
29 checks passed
@chenBright
chenBright deleted the fix-span-ut branch November 19, 2026 06:03
darion-yaphet pushed a commit to darion-yaphet/brpc that referenced this pull request Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status/ready-to-merge Required approvals and checks are satisfied, with no blocking feedback remaining

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants