diff --git a/p2p/base/connection.cc b/p2p/base/connection.cc index a04f318acb..1d674e2bcb 100644 --- a/p2p/base/connection.cc +++ b/p2p/base/connection.cc @@ -834,6 +834,11 @@ void Connection::Prune() { void Connection::Destroy() { RTC_DCHECK_RUN_ON(network_thread_); + if (pending_delete_) + return; + + pending_delete_ = true; + RTC_DLOG(LS_VERBOSE) << ToString() << ": Connection destroyed"; // Fire the 'destroyed' event before deleting the object. This is done diff --git a/p2p/base/connection.h b/p2p/base/connection.h index 8254706318..a7b3490757 100644 --- a/p2p/base/connection.h +++ b/p2p/base/connection.h @@ -366,6 +366,9 @@ class Connection : public CandidatePairInterface, public sigslot::has_slots<> { rtc::RateTracker recv_rate_tracker_; rtc::RateTracker send_rate_tracker_; int64_t last_send_data_ = 0; + // Set to true when deletion has been scheduled and must not be done again. + // See `Destroy()` for more details. + bool pending_delete_ RTC_GUARDED_BY(network_thread_) = false; private: // Update the local candidate based on the mapped address attribute.