diff --git a/CHANGELOG.md b/CHANGELOG.md index c4e6f622ad..99b8eadfca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # Changelog +### Next + +* `Worker`: Add `Transport::Destroying()` protected method ([PR #1114](https://github.com/versatica/mediasoup/pull/1114)). + + ### 3.12.5 * `DataConsumer`: Fix removed 'bufferedamountlow' notification ([PR #1113](https://github.com/versatica/mediasoup/pull/1113)). diff --git a/worker/include/RTC/Transport.hpp b/worker/include/RTC/Transport.hpp index 87e5e81909..1ce6812cf0 100644 --- a/worker/include/RTC/Transport.hpp +++ b/worker/include/RTC/Transport.hpp @@ -144,6 +144,7 @@ namespace RTC protected: // Must be called from the subclass. + void Destroying(); void Connected(); void Disconnected(); void DataReceived(size_t len) diff --git a/worker/src/RTC/DirectTransport.cpp b/worker/src/RTC/DirectTransport.cpp index fe28591730..903881170b 100644 --- a/worker/src/RTC/DirectTransport.cpp +++ b/worker/src/RTC/DirectTransport.cpp @@ -28,6 +28,10 @@ namespace RTC { MS_TRACE(); + // Tell the Transport parent class that we are about to destroy + // the class instance. + Destroying(); + this->shared->channelMessageRegistrator->UnregisterHandler(this->id); } diff --git a/worker/src/RTC/PipeTransport.cpp b/worker/src/RTC/PipeTransport.cpp index 39bc2a0ead..d46624a649 100644 --- a/worker/src/RTC/PipeTransport.cpp +++ b/worker/src/RTC/PipeTransport.cpp @@ -117,6 +117,10 @@ namespace RTC { MS_TRACE(); + // Tell the Transport parent class that we are about to destroy + // the class instance. + Destroying(); + this->shared->channelMessageRegistrator->UnregisterHandler(this->id); delete this->udpSocket; diff --git a/worker/src/RTC/PlainTransport.cpp b/worker/src/RTC/PlainTransport.cpp index a90ecdd8dc..6a461dc78d 100644 --- a/worker/src/RTC/PlainTransport.cpp +++ b/worker/src/RTC/PlainTransport.cpp @@ -206,6 +206,10 @@ namespace RTC { MS_TRACE(); + // Tell the Transport parent class that we are about to destroy + // the class instance. + Destroying(); + this->shared->channelMessageRegistrator->UnregisterHandler(this->id); delete this->udpSocket; diff --git a/worker/src/RTC/Transport.cpp b/worker/src/RTC/Transport.cpp index 65e0b57c73..3bf589286b 100644 --- a/worker/src/RTC/Transport.cpp +++ b/worker/src/RTC/Transport.cpp @@ -182,9 +182,6 @@ namespace RTC { MS_TRACE(); - // Set the destroying flag. - this->destroying = true; - // The destructor must delete and clear everything silently. // Delete all Producers. @@ -1594,6 +1591,13 @@ namespace RTC } } + void Transport::Destroying() + { + MS_TRACE(); + + this->destroying = true; + } + void Transport::Connected() { MS_TRACE(); diff --git a/worker/src/RTC/WebRtcTransport.cpp b/worker/src/RTC/WebRtcTransport.cpp index 4ec9065d50..000b389dbb 100644 --- a/worker/src/RTC/WebRtcTransport.cpp +++ b/worker/src/RTC/WebRtcTransport.cpp @@ -300,6 +300,11 @@ namespace RTC { MS_TRACE(); + // We need to tell the Transport parent class that we are about to destroy + // the class instance. This is because child's destructor runs before + // parent's destructor. See comment in Transport::OnSctpAssociationSendData(). + Destroying(); + this->shared->channelMessageRegistrator->UnregisterHandler(this->id); // Must delete the DTLS transport first since it will generate a DTLS alert