mirror of
https://github.com/XRPLF/rippled.git
synced 2026-04-29 15:37:57 +00:00
Fix std::bad_weak_ptr crash in OTelGaugeImpl constructor
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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<GaugeImpl>(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<OTelGaugeImpl*>(state);
|
||||
|
||||
Reference in New Issue
Block a user