Fix: relayd: viewer_stream leak causes assertion failure on exit
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 11 Oct 2024 20:26:59 +0000 (16:26 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 17 Oct 2024 18:37:20 +0000 (14:37 -0400)
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 <jeremie.galarneau@efficios.com>
Change-Id: I7d5d5d3a77f6f08744b712d9ef1233a1d19a7124

src/bin/lttng-relayd/live.cpp

index 079ac6b0b2a6e4d2e5a5ddb55c6244eb1c3d6c01..6426330f5a97298766cff5594e634d815ca71c58 100644 (file)
@@ -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);
        }
This page took 0.026625 seconds and 4 git commands to generate.