Skip to content

Commit

Permalink
Fix concurrency issues in ErizoAPI/MediaStream (#1442)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcague authored Jul 25, 2019
1 parent 603a863 commit a62f59a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
13 changes: 7 additions & 6 deletions erizoAPI/MediaStream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ MediaStream::~MediaStream() {
}

void MediaStream::closeEvents() {
boost::mutex::scoped_lock lock(mutex);
has_stats_callback_ = false;
has_event_callback_ = false;
if (!uv_is_closing(reinterpret_cast<uv_handle_t*>(async_stats_))) {
Expand Down Expand Up @@ -434,27 +435,27 @@ NAN_METHOD(MediaStream::onMediaStreamEvent) {
}

void MediaStream::notifyStats(const std::string& message) {
if (!this->has_stats_callback_) {
boost::mutex::scoped_lock lock(mutex);
if (!has_stats_callback_) {
return;
}
if (!async_stats_) {
return;
}
boost::mutex::scoped_lock lock(mutex);
this->stats_messages.push(message);
stats_messages.push(message);
async_stats_->data = this;
uv_async_send(async_stats_);
}

void MediaStream::notifyMediaStreamEvent(const std::string& type, const std::string& message) {
if (!this->has_event_callback_) {
boost::mutex::scoped_lock lock(mutex);
if (!has_event_callback_) {
return;
}
if (!async_event_) {
return;
}
boost::mutex::scoped_lock lock(mutex);
this->event_messages.push(std::make_pair(type, message));
event_messages.push(std::make_pair(type, message));
async_event_->data = this;
uv_async_send(async_event_);
}
Expand Down
6 changes: 4 additions & 2 deletions erizoAPI/WebRtcConnection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ void WebRtcConnection::close() {
me.reset();
}

boost::mutex::scoped_lock lock(mutex);

if (!uv_is_closing(reinterpret_cast<uv_handle_t*>(async_))) {
ELOG_DEBUG("%s, message: Closing handle", toLog());
uv_close(reinterpret_cast<uv_handle_t*>(async_), destroyWebRtcConnectionAsyncHandle);
Expand Down Expand Up @@ -465,8 +467,8 @@ void WebRtcConnection::notifyEvent(erizo::WebRTCEvent event, const std::string&
if (!async_) {
return;
}
this->event_status.push(event);
this->event_messages.push(message);
event_status.push(event);
event_messages.push(message);
async_->data = this;
uv_async_send(async_);
}
Expand Down

0 comments on commit a62f59a

Please sign in to comment.