Skip to content

Commit

Permalink
Check to see if the disconnector has outlived the ForwardingEgressPro…
Browse files Browse the repository at this point in the history
…vider
  • Loading branch information
dagardner-nv committed Oct 11, 2023
1 parent 96dda60 commit 111d7f8
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions cpp/mrc/include/mrc/node/source_properties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ class MultiIngressAcceptor : public virtual MultiSourceProperties<T, KeyT>, publ
};

template <typename T>
class ForwardingEgressProvider : public ReadableProvider<T>
class ForwardingEgressProvider : public ReadableProvider<T>,
public std::enable_shared_from_this<ForwardingEgressProvider<T>>
{
protected:
class ForwardingEdge : public edge::IEdgeReadable<T>
Expand All @@ -228,9 +229,14 @@ class ForwardingEgressProvider : public ReadableProvider<T>
{
auto inner_edge = std::make_shared<ForwardingEdge>(*this);

inner_edge->add_disconnector([this]() {
// Only call the on_complete if we have been connected
this->on_complete();
// It is possible for the lambda to outlive this object, so we need to capture a weak_ptr
std::weak_ptr<ForwardingEgressProvider<T>> weak_ptr = this->shared_from_this();
inner_edge->add_disconnector([weak_egress_provider = std::move(weak_ptr)]() {
if (auto egress_provider = weak_egress_provider.lock())
{
// Only call the on_complete if we have been connected
egress_provider->on_complete();
}
});

ReadableProvider<T>::init_owned_edge(inner_edge);
Expand Down

0 comments on commit 111d7f8

Please sign in to comment.