From: Jérémie Galarneau Date: Fri, 11 Oct 2024 20:26:59 +0000 (-0400) Subject: Fix: relayd: viewer_stream leak causes assertion failure on exit X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=25e301be1a087831ccf7e6652a25a695011b03e2;p=lttng-tools.git Fix: relayd: viewer_stream leak causes assertion failure on exit Observed issue ============== Running the test proposed in change #11584[1], the relay daemon aborts when destroying the viewer_streams_ht as it is not empty. Cause ===== A viewer stream reference is leaked when sending streams to the live client causing them to remain published in the viewer_streams_ht beyond the lifetime of the viewer_connection. The send_viewer_streams() function operates in two phases. First, it iterates over the viewer_streams_ht to find streams that belong to the target session and have not been sent yet. In the second phase, it iterates over the session's unannounced stream list. The commit message of 98b82dfa2 gives more background on the role of the unannounced stream list. When a viewer stream is created, two references are acquired: - one belongs to the global viewer_streams_ht, - the other belongs to the unannounced stream list. When the viewer stream is eventually sent to the client, it is removed from the unannounced stream list and that reference must be dropped. Unfortunately, the reference is not dropped during the first phase. Solution ======== Put the reference of the viewer streams that are sent during the first phase of send_viewer_streams(). Known drawbacks =============== None. [1] https://review.lttng.org/c/lttng-tools/+/11584 Signed-off-by: Jérémie Galarneau Change-Id: I7d5d5d3a77f6f08744b712d9ef1233a1d19a7124 --- diff --git a/src/bin/lttng-relayd/live.cpp b/src/bin/lttng-relayd/live.cpp index 079ac6b0b..6426330f5 100644 --- a/src/bin/lttng-relayd/live.cpp +++ b/src/bin/lttng-relayd/live.cpp @@ -355,6 +355,7 @@ static ssize_t send_viewer_streams(struct lttcomm_sock *sock, pthread_mutex_lock(&viewer_session->unannounced_stream_list_lock); cds_list_del_rcu(&vstream->viewer_stream_node); + viewer_stream_put(vstream); pthread_mutex_unlock(&viewer_session->unannounced_stream_list_lock); viewer_stream_put(vstream); }