From c5ce3927e9c05390d39ba099baa130be9927341f Mon Sep 17 00:00:00 2001 From: Francis Deslauriers Date: Thu, 24 Feb 2022 16:51:50 -0500 Subject: [PATCH] Fix: src.ctf.lttng-live: consider empty metadata packet as retry MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit When clearing a live session, it's possible for the Relay to know that metadata is available even though it has not yet received it from the consumer. In such cases, the relay will send a `LTTNG_VIEWER_METADATA_OK` reply with a zero length metadata packet. The viewer needs to interpret that as "please try again later". In fact, the viewer needs to keep requesting metadata from the relay until it receives either a `LTTNG_VIEWER_NO_NEW_METADATA` status or an error status. Signed-off-by: Francis Deslauriers Signed-off-by: Jérémie Galarneau Change-Id: Ief33f1a43ec827e211a2f4f2ace623e9d3254246 Reviewed-on: https://review.lttng.org/c/babeltrace/+/3763 --- src/plugins/ctf/lttng-live/viewer-connection.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/plugins/ctf/lttng-live/viewer-connection.cpp b/src/plugins/ctf/lttng-live/viewer-connection.cpp index 804a88d8..7960b50e 100644 --- a/src/plugins/ctf/lttng-live/viewer-connection.cpp +++ b/src/plugins/ctf/lttng-live/viewer-connection.cpp @@ -1288,6 +1288,17 @@ lttng_live_get_one_metadata_packet(struct lttng_live_trace *trace, FILE *fp, siz } len = be64toh(rp.len); + if (len == 0) { + /* + * We received a `LTTNG_VIEWER_METADATA_OK` with a packet + * length of 0. This means we must try again. This scenario + * arises when a clear command is performed on an lttng session. + */ + BT_COMP_LOGD( + "Expecting a metadata packet of size 0. Retry to get a packet from the relay."); + goto empty_metadata_packet_retry; + } + BT_COMP_LOGD("Writing %" PRIu64 " bytes to metadata", len); if (len <= 0) { BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Erroneous response length"); @@ -1319,6 +1330,7 @@ lttng_live_get_one_metadata_packet(struct lttng_live_trace *trace, FILE *fp, siz goto end; } +empty_metadata_packet_retry: *reply_len = len; status = LTTNG_LIVE_GET_ONE_METADATA_STATUS_OK; -- 2.34.1