diff --git a/lib-protocol/source/channel.cpp b/lib-protocol/source/channel.cpp index 82926821e..8f9813093 100644 --- a/lib-protocol/source/channel.cpp +++ b/lib-protocol/source/channel.cpp @@ -131,19 +131,20 @@ task Channel::Open() noexcept { task Channel::Shut() noexcept { co_await Post([&]() { channel_->Close(); - channel_->UnregisterObserver(); - const auto state(channel_->state()); if (Verbose) Log() << "closed channel in state " << webrtc::DataChannelInterface::DataStateString(state) << std::endl; if (state != webrtc::DataChannelInterface::kClosed) Stop(); + }); + + co_await Pump::Shut(); + co_await Post([&]() { + channel_->UnregisterObserver(); channel_ = nullptr; peer_ = nullptr; }); - - co_await Pump::Shut(); } template