Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[videoroom] Fix race condition when joining and destroying the session #1911

Merged
merged 1 commit into from
Jan 13, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions plugins/janus_videoroom.c
Original file line number Diff line number Diff line change
Expand Up @@ -5267,6 +5267,19 @@ static void *janus_videoroom_handler(void *data) {
janus_mutex_unlock(&videoroom->mutex);
goto error;
}
janus_mutex_lock(&sessions_mutex);
session = janus_videoroom_lookup_session(msg->handle);
if(!session) {
janus_mutex_unlock(&sessions_mutex);
JANUS_LOG(LOG_ERR, "No session associated with this handle...\n");
janus_videoroom_message_free(msg);
continue;
}
if(g_atomic_int_get(&session->destroyed)) {
janus_mutex_unlock(&sessions_mutex);
janus_videoroom_message_free(msg);
continue;
}
json_t *feed = json_object_get(root, "feed");
guint64 feed_id = json_integer_value(feed);
json_t *pvt = json_object_get(root, "private_id");
Expand All @@ -5286,6 +5299,7 @@ static void *janus_videoroom_handler(void *data) {
JANUS_LOG(LOG_ERR, "Invalid element (substream/spatial_layer should be 0, 1 or 2)\n");
error_code = JANUS_VIDEOROOM_ERROR_INVALID_ELEMENT;
g_snprintf(error_cause, 512, "Invalid value (substream/spatial_layer should be 0, 1 or 2)");
janus_mutex_unlock(&sessions_mutex);
janus_mutex_unlock(&videoroom->mutex);
goto error;
}
Expand All @@ -5296,6 +5310,7 @@ static void *janus_videoroom_handler(void *data) {
JANUS_LOG(LOG_ERR, "Invalid element (temporal/temporal_layer should be 0, 1 or 2)\n");
error_code = JANUS_VIDEOROOM_ERROR_INVALID_ELEMENT;
g_snprintf(error_cause, 512, "Invalid value (temporal/temporal_layer should be 0, 1 or 2)");
janus_mutex_unlock(&sessions_mutex);
janus_mutex_unlock(&videoroom->mutex);
goto error;
}
Expand All @@ -5305,6 +5320,7 @@ static void *janus_videoroom_handler(void *data) {
JANUS_LOG(LOG_ERR, "No such feed (%"SCNu64")\n", feed_id);
error_code = JANUS_VIDEOROOM_ERROR_NO_SUCH_FEED;
g_snprintf(error_cause, 512, "No such feed (%"SCNu64")", feed_id);
janus_mutex_unlock(&sessions_mutex);
janus_mutex_unlock(&videoroom->mutex);
goto error;
} else {
Expand All @@ -5319,6 +5335,7 @@ static void *janus_videoroom_handler(void *data) {
JANUS_LOG(LOG_ERR, "Unauthorized (this room requires a valid private_id)\n");
error_code = JANUS_VIDEOROOM_ERROR_UNAUTHORIZED;
g_snprintf(error_cause, 512, "Unauthorized (this room requires a valid private_id)");
janus_mutex_unlock(&sessions_mutex);
janus_mutex_unlock(&videoroom->mutex);
goto error;
}
Expand Down Expand Up @@ -5352,6 +5369,7 @@ static void *janus_videoroom_handler(void *data) {
JANUS_LOG(LOG_ERR, "Can't offer an SDP with no audio, video or data\n");
error_code = JANUS_VIDEOROOM_ERROR_INVALID_SDP;
g_snprintf(error_cause, 512, "Can't offer an SDP with no audio, video or data");
janus_mutex_unlock(&sessions_mutex);
goto error;
}
subscriber->audio = audio ? json_is_true(audio) : TRUE; /* True by default */
Expand Down Expand Up @@ -5393,6 +5411,7 @@ static void *janus_videoroom_handler(void *data) {
janus_refcount_decrease(&owner->session->ref);
janus_refcount_decrease(&owner->ref);
}
janus_mutex_unlock(&sessions_mutex);
event = json_object();
json_object_set_new(event, "videoroom", json_string("attached"));
json_object_set_new(event, "room", json_integer(subscriber->room_id));
Expand Down