From 8af6af6b2aa4a77819701c910a13e76a41bd1540 Mon Sep 17 00:00:00 2001 From: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com> Date: Tue, 17 Mar 2026 10:55:41 +0000 Subject: [PATCH] Fix std::bad_weak_ptr crash in OTelGaugeImpl constructor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove illegal shared_from_this() call from OTelGaugeImpl constructor. The shared_ptr control block is not yet associated with the object during construction, causing std::bad_weak_ptr when [insight] server=otel is configured. The weakSelf variable was dead code — never used — since the callback captures `this` directly via void* state. The raw pointer is safe because RemoveCallback() is called in the destructor. Co-Authored-By: Claude Opus 4.6 --- src/libxrpl/beast/insight/OTelCollector.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libxrpl/beast/insight/OTelCollector.cpp b/src/libxrpl/beast/insight/OTelCollector.cpp index 46e6563fd8..203326c32a 100644 --- a/src/libxrpl/beast/insight/OTelCollector.cpp +++ b/src/libxrpl/beast/insight/OTelCollector.cpp @@ -562,8 +562,8 @@ OTelGaugeImpl::OTelGaugeImpl( { // Register the async callback that the SDK calls during collection. // The callback reads the atomic value and reports it to the observer. - // We capture a weak_ptr to avoid preventing destruction. - auto weakSelf = std::weak_ptr(shared_from_this()); + // The raw `this` pointer is safe here because RemoveCallback() is + // called in the destructor before `this` becomes invalid. m_gauge->AddCallback( [](opentelemetry::metrics::ObserverResult result, void* state) { auto* self = static_cast(state);