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 <jeremie.galarneau@efficios.com>
Change-Id: I7d5d5d3a77f6f08744b712d9ef1233a1d19a7124