From 41d436e56e493b1400b4c7da2e0dceafe67b4a35 Mon Sep 17 00:00:00 2001 From: Branko Subasic Date: Mon, 7 Mar 2022 09:14:46 +0100 Subject: [PATCH] gst-rtsp-server: fix race in rtsp-client When tunneling over HTTP, if connection on the second channel happens before the control timer is created we may trigger an assert in rtsp_ctrl_timeout_remove(). Avoid that by taking the priv->lock before attaching the client thread to the context. Fixes #1025 Part-of: --- subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-client.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-client.c b/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-client.c index 4aec1f2..6e9de4c 100644 --- a/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-client.c +++ b/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-client.c @@ -5304,12 +5304,15 @@ gst_rtsp_client_attach (GstRTSPClient * client, GMainContext * context) gst_rtsp_watch_set_send_backlog (priv->watch, 0, WATCH_BACKLOG_SIZE); + /* take the lock before attaching the client watch, so that the client thread + * can not access the control channel timer until it's properly in place */ + g_mutex_lock (&priv->lock); + GST_INFO ("client %p: attaching to context %p", client, context); res = gst_rtsp_watch_attach (priv->watch, context); /* Setting up a timeout for the RTSP control channel until a session * is up where it is handling timeouts. */ - g_mutex_lock (&priv->lock); /* remove old timeout if any */ rtsp_ctrl_timeout_remove_unlocked (client->priv); -- 2.7.4