Don't unregister an observer while inside an observer callback.

PiperOrigin-RevId: 521860015
This commit is contained in:
hai007
2023-04-04 14:05:32 -07:00
committed by Copybara-Service
parent 13f7fb7966
commit f8f9c4fd4e
@@ -67,6 +67,7 @@ WebRtcSocket::WebRtcSocket(
WebRtcSocket::~WebRtcSocket() {
NEARBY_LOGS(INFO) << "WebRtcSocket::~WebRtcSocket(" << name_
<< ") this: " << this;
data_channel_->UnregisterObserver();
Close();
NEARBY_LOGS(INFO) << "WebRtcSocket::~WebRtcSocket(" << name_
<< ") this: " << this << " done";
@@ -108,7 +109,6 @@ void WebRtcSocket::OnStateChange() {
NEARBY_LOG(
ERROR,
"WebRtcSocket::OnStateChange() unregistering data channel observer.");
data_channel_->UnregisterObserver();
// This will trigger a destruction of the owning connection flow
// We implicitly depend on the |socket_listener_| to offload from
// the signaling thread so it does not get blocked.