Skip to content

Commit

Permalink
Fix wrong set usage
Browse files Browse the repository at this point in the history
  • Loading branch information
ibc committed Apr 9, 2024
1 parent 6b45209 commit 3b23846
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions worker/include/RTC/WebRtcServer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ namespace RTC
absl::flat_hash_map<std::string, RTC::WebRtcTransport*> mapLocalIceUsernameFragmentWebRtcTransport;
// Map of WebRtcTransports indexed by TransportTuple.hash.
absl::flat_hash_map<uint64_t, RTC::WebRtcTransport*> mapTupleWebRtcTransport;
// Whether the destructor has been called.
bool closing{ false };
};
} // namespace RTC

Expand Down
11 changes: 10 additions & 1 deletion worker/src/RTC/WebRtcServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ namespace RTC
{
MS_TRACE();

this->closing = true;

this->shared->channelMessageRegistrator->UnregisterHandler(this->id);

for (auto& item : this->udpSocketOrTcpServers)
Expand Down Expand Up @@ -497,7 +499,14 @@ namespace RTC
this->webRtcTransports.find(webRtcTransport) != this->webRtcTransports.end(),
"WebRtcTransport not handled");

this->webRtcTransports.erase(webRtcTransport);
// NOTE: If WebRtcServer is closing then do not remove the transport from
// the set since it would modify the set while the WebRtcServer destructor
// is iterating it.
// See: https://github.com/versatica/mediasoup/pull/1369#issuecomment-2044672247
if (!this->closing)
{
this->webRtcTransports.erase(webRtcTransport);
}
}

inline void WebRtcServer::OnWebRtcTransportLocalIceUsernameFragmentAdded(
Expand Down

0 comments on commit 3b23846

Please sign in to comment.