From 61c935bbd8af2b87cbde43bc7c60a031aa1525eb Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Fri, 25 Oct 2019 17:32:42 -0400 Subject: [PATCH] Fix: source.ctf.lttng-live: assertion on equal messages MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The following assertion fails when consuming a per-pid trace of short-lived applications. (╯°□°)╯︵ ┻━┻ muxing.c:849: common_muxing_compare_messages(): Assertion `left_msg != right_msg` failed. The live source performs a muxing step during which it can see that a trace has ended. When that happens, the trace is removed from the array of traces and the iteration on that array resumes from the beginning. This causes the message comparator to assert as two identical messages can be compared. Not reseting the trace index to 0 causes the iteration to continue from the same position in the array. This is fine since the "fast" variant of the glib pointer array removal function replaces the removed pointer by the last one. This is both more efficient and solved the problem of comparing a message to itself (the oldest message) during a second pass on the traces array. Signed-off-by: Jérémie Galarneau Change-Id: I5045a0483b17f0bcb48ff7eb0d88f82bf19f68d4 Reviewed-on: https://review.lttng.org/c/babeltrace/+/2262 CI-Build: Simon Marchi Tested-by: jenkins Reviewed-by: Simon Marchi --- src/plugins/ctf/lttng-live/lttng-live.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/plugins/ctf/lttng-live/lttng-live.c b/src/plugins/ctf/lttng-live/lttng-live.c index f787ea75..e9007acb 100644 --- a/src/plugins/ctf/lttng-live/lttng-live.c +++ b/src/plugins/ctf/lttng-live/lttng-live.c @@ -1120,11 +1120,6 @@ enum lttng_live_iterator_status next_stream_iterator_for_session( BT_ASSERT_DBG(session->traces); - /* - * Use while loops here rather then for loops so we can restart the - * iteration if an element is removed from the array during the - * looping. - */ while (trace_idx < session->traces->len) { bool trace_is_ended = false; struct lttng_live_stream_iterator *stream_iter; @@ -1175,8 +1170,13 @@ enum lttng_live_iterator_status next_stream_iterator_for_session( } trace_idx++; } else { - g_ptr_array_remove_index_fast(session->traces, trace_idx); - trace_idx = 0; + /* + * trace_idx is not incremented since + * g_ptr_array_remove_index_fast replaces the + * element at trace_idx with the array's last element. + */ + g_ptr_array_remove_index_fast(session->traces, + trace_idx); } } if (youngest_candidate_stream_iter) { -- 2.34.1