From da5ec2184fac628bf9fd3990772d71a3938e353e Mon Sep 17 00:00:00 2001 From: Lionel Nicolas Date: Sat, 12 Jun 2021 12:02:53 -0400 Subject: [PATCH] Fix deadlock when destroying RTSP mountpoint while reconnecting --- plugins/janus_streaming.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/plugins/janus_streaming.c b/plugins/janus_streaming.c index 25c938c205a..ceaa27f3aa4 100644 --- a/plugins/janus_streaming.c +++ b/plugins/janus_streaming.c @@ -6489,14 +6489,18 @@ static int janus_streaming_rtsp_connect_to_server(janus_streaming_mountpoint *mp int asport = 0, asport_rtcp = 0; multiple_fds audio_fds = {-1, -1}; - if(g_atomic_int_get(&mp->destroyed)) { - curl_easy_cleanup(curl); - g_free(curldata->buffer); - g_free(curldata); - return -8; + while (!janus_mutex_trylock(&mountpoints_mutex)) { + if(g_atomic_int_get(&mp->destroyed)) { + JANUS_LOG(LOG_WARN, "[%s] Destroying mountpoint while trying to reconnect, aborting\n", mp->name); + curl_easy_cleanup(curl); + g_free(curldata->buffer); + g_free(curldata); + return -8; + } + + g_usleep(1000); } - janus_mutex_lock(&mountpoints_mutex); /* Parse both video and audio first before proceed to setup as curldata will be reused */ int vresult = -1; if(dovideo) {