Sponsored Content
Skip to content

fix: Switch to boost::coroutine2 - #6372

Merged
bthomee merged 48 commits into
developfrom
pratik/Fix_asan_boost_coroutine_issues
Mar 16, 2026
Merged

fix: Switch to boost::coroutine2#6372
bthomee merged 48 commits into
developfrom
pratik/Fix_asan_boost_coroutine_issues

Conversation

@pratikmankawde

@pratikmankawde pratikmankawde commented Feb 16, 2026

Copy link
Copy Markdown
Contributor

High Level Overview of Change

Switch boost::coroutine with boost::coroutine2, to fix ASAN issues

Context of Change

ASAN wasn't able to keep track of boost::coroutine context switches. It would lead to many false positives from ASAN. Switched to boost::coroutine2 and ucontext, allows ASAN to know about the context switches advertized by boost::fiber class. This leads to more cleaner ASAN analysis.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (non-breaking change that only restructures code)
  • Performance (increase or change in throughput and/or latency)
  • Tests (you added tests for code that already exists, or your new feature included in this PR)
  • Documentation update
  • Chore (no impact to binary, e.g. .gitignore, formatting, dropping support for older tooling)
  • Release
    Test based testing.

Signed-off-by: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com>
@pratikmankawde pratikmankawde added the DraftRunCI Normally CI does not run on draft PRs. This opts in. label Feb 16, 2026
@codecov

codecov Bot commented Feb 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.8%. Comparing base (b585dc7) to head (866250f).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           develop   #6372     +/-   ##
=========================================
- Coverage     79.8%   79.8%   -0.0%     
=========================================
  Files          878     878             
  Lines        67887   67888      +1     
  Branches      7549    7555      +6     
=========================================
- Hits         54206   54197      -9     
- Misses       13681   13691     +10     
Files with missing lines Coverage Δ
include/xrpl/core/Coro.ipp 100.0% <100.0%> (ø)
include/xrpl/core/JobQueue.h 100.0% <ø> (ø)

... and 6 files with indirect coverage changes

Impacted file tree graph

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Signed-off-by: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com>
Signed-off-by: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com>
Signed-off-by: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com>
Signed-off-by: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com>
Signed-off-by: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com>
Comment thread sanitizers/suppressions/asan.supp
Comment thread sanitizers/suppressions/asan.supp Outdated
Signed-off-by: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com>
…RPLF/rippled into pratik/Fix_asan_boost_coroutine_issues
Comment thread sanitizers/suppressions/asan.supp Outdated
Signed-off-by: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com>
Signed-off-by: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com>
Signed-off-by: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com>
Signed-off-by: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com>
Comment thread .github/workflows/reusable-build-test-config.yml Outdated
…RPLF/rippled into pratik/Fix_asan_boost_coroutine_issues
Signed-off-by: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com>
Signed-off-by: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com>
Signed-off-by: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com>
Signed-off-by: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com>
Signed-off-by: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com>
Signed-off-by: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com>
@pratikmankawde pratikmankawde added QE test required RippleX QE Team must look at this PR. and removed QE test desired RippleX QE Team should consider looking at this PR. labels Mar 10, 2026

@godexsoft godexsoft 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.

Leaving some questions.

Comment thread cmake/deps/Boost.cmake Outdated
)
endif()

# if (SANITIZERS_ENABLED AND is_clang)

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.

Is this comment still needed here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was testing if we need to instrument boost with asan or not. It was flaky a bit. Removing now.

Comment thread include/xrpl/core/Coro.ipp
Comment thread sanitizers/suppressions/asan.supp Outdated
#interceptor_via_fun:swapcontext
#interceptor_via_fun:makecontext
#interceptor_via_fun:boost::context::basic_fixedsize_stack*deallocate
#interceptor_via_fun:boost::context::fiber::~fiber

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.

Does this work in practice? i recall these kind of suppressions did not actually work for me because suppressions "only work on your code", not library code.. or so i read online.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These are commented anyway. I put them for GCC actually, since we can't pass ignorelist at compile time to gcc.

Comment thread conanfile.py Outdated
self.options["boost"].visibility = "global"
if self.settings.compiler in ["clang", "gcc"]:
self.options["boost"].without_cobalt = True
self.options["boost"].without_context = False

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.

Does this not duplicate lines 61-63?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

cleared

Signed-off-by: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com>
Signed-off-by: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com>
Signed-off-by: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com>

@godexsoft godexsoft 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.

👍

@pratikmankawde pratikmankawde added the Ready to merge *PR author* thinks it's ready to merge. Has passed code review. Perf sign-off may still be required. label Mar 16, 2026
@bthomee
bthomee enabled auto-merge (squash) March 16, 2026 14:55
@bthomee
bthomee merged commit 9838162 into develop Mar 16, 2026
3 checks passed
@bthomee
bthomee deleted the pratik/Fix_asan_boost_coroutine_issues branch March 16, 2026 15:34
@bthomee

bthomee commented Mar 20, 2026

Copy link
Copy Markdown
Collaborator

/ai-review

@xrplf-ai-reviewer xrplf-ai-reviewer Bot 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.

Review by Claude Opus 4.6 · Prompt: V12

Comment thread conanfile.py
Comment thread conan/profiles/sanitizers
Comment thread cmake/deps/Boost.cmake
[this, fn = std::forward<F>(f)](
boost::coroutines::asymmetric_coroutine<void>::push_type& do_yield) {
boost::coroutines2::asymmetric_coroutine<void>::push_type& do_yield) {
yield_ = &do_yield;

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.

Dangling raw pointer to coroutine push_type parameter

The yield_ member is assigned the address of do_yield, which is the push_type& parameter passed into the coroutine lambda body. While this pointer is valid during coroutine execution (the parameter lives in the coroutine frame), it becomes a dangling pointer once the coroutine completes or is destroyed. The migration from boost::coroutines to boost::coroutines2 preserves this pre-existing pattern, but boost::coroutines2 has stricter lifetime semantics: after fn(shared_from_this()) returns and the coroutine lambda exits, do_yield is destroyed. Any subsequent call through yield_ (e.g., via a stale Coro reference) would access freed memory. The finished_ debug flag partially guards against this but is only active in debug builds.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There is not path in the code which can create or preserve such a dangling ref. to Coro.
yield can only be called from inside a coroutine's stack, there are no semantics to call it from outside and hence reference any dangling yield_. So the current implementation is safe.

Comment thread .github/workflows/reusable-build-test-config.yml
Comment thread include/xrpl/core/Coro.ipp
Comment thread cmake/deps/Boost.cmake
Comment thread include/xrpl/core/Coro.ipp
Comment thread include/xrpl/core/Coro.ipp
Comment thread .github/workflows/reusable-build-test-config.yml
ximinez added a commit that referenced this pull request Apr 8, 2026
ximinez added a commit that referenced this pull request Apr 9, 2026
ximinez added a commit that referenced this pull request Apr 15, 2026
@bthomee
bthomee requested a review from Copilot April 20, 2026 14:29

@xrplf-ai-reviewer xrplf-ai-reviewer Bot 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.

Three correctness issues flagged inline: wrong coroutine2 type name in Coro.ipp, a no-op default_options mutation in conanfile.py, and missing context-impl=ucontext for the TSAN path in the sanitizers profile.

Review by Claude Opus 4.6 · Prompt: V15

Comment thread conan/profiles/sanitizers
Comment thread conanfile.py
Comment thread include/xrpl/core/Coro.ipp

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.

Pull request overview

This PR migrates the core JobQueue coroutine implementation from Boost.Coroutine to Boost.Coroutine2 (with Boost.Context/ucontext) to improve AddressSanitizer (ASAN) accuracy around context switches, and updates build/config tooling to match.

Changes:

  • Replace Boost.Coroutine usage in JobQueue with Boost.Coroutine2 and a protected fixed-size stack allocator.
  • Update Conan/CMake/CI sanitizer configuration to build/link Boost.Context appropriately and set ASAN runtime options.
  • Remove now-unneeded ASAN suppressions and update spelling dictionary.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
sanitizers/suppressions/asan.supp Removes Boost-related suppressions that should no longer be needed with the coroutine2/ucontext approach.
include/xrpl/core/JobQueue.h Switches coroutine member types and includes to Boost.Coroutine2/Boost.Context.
include/xrpl/core/Coro.ipp Updates coroutine construction to use protected_fixedsize_stack and coroutine2 API.
cspell.config.yaml Adds fcontext to spelling allowlist.
conanfile.py Adjusts Boost options/components and adds sanitizer-driven configuration logic.
conan/profiles/sanitizers Adds sanitizer defines and Boost build options for ucontext/ASAN annotations.
cmake/deps/Boost.cmake Switches linked Boost component from coroutine to context; adds gcc14 warning workaround and ASAN-related defines.
cmake/XrplInterface.cmake Updates deprecation-warning suppression macro for Coroutine2.
.github/workflows/reusable-build-test-config.yml Extends sanitizer job timeout and refines ASAN_OPTIONS (plus gcc-specific tweak).

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

Comment thread conan/profiles/sanitizers
Comment thread include/xrpl/core/Coro.ipp
Comment thread conanfile.py
@mvadari mvadari added this to the 3.2.0 milestone May 20, 2026
beartec-jpg pushed a commit to beartec-jpg/FalconLedger that referenced this pull request Jun 1, 2026
ASAN wasn't able to keep track of `boost::coroutine` context switches, and would lead to many false positives being detected. By switching to `boost::coroutine2` and `ucontext`, ASAN is able to know about the context switches advertised by the `boost::fiber` class, which in turn leads to more cleaner ASAN analysis.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

QE test required RippleX QE Team must look at this PR. Ready to merge *PR author* thinks it's ready to merge. Has passed code review. Perf sign-off may still be required.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants