From d995f382e348c509c15673aba195c3ecb624391c Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Mon, 28 Oct 2019 23:29:53 -0400 Subject: [PATCH] Fix: relayd: live: some listed sessions are not attacheable MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The list sessions command currently returns sessions that do not have a current trace chunk. This can be caused by the session either being destroyed or being so young that it hasn't had a trace chunk created against it yet. In both cases, such sessions would not be attacheable in their current condition. This fix omits them from from the listing to reduce the number of failures at the "attach session" and "attach stream" step. Signed-off-by: Jérémie Galarneau --- src/bin/lttng-relayd/live.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/bin/lttng-relayd/live.c b/src/bin/lttng-relayd/live.c index 74c28a457..8c4f501aa 100644 --- a/src/bin/lttng-relayd/live.c +++ b/src/bin/lttng-relayd/live.c @@ -831,9 +831,18 @@ int viewer_list_sessions(struct relay_connection *conn) health_code_update(); + pthread_mutex_lock(&session->lock); if (session->connection_closed) { /* Skip closed session */ - continue; + goto next_session; + } + if (!session->current_trace_chunk) { + /* + * Skip un-attachable session. It is either + * being destroyed or has not had a trace + * chunk created against it yet. + */ + goto next_session; } if (count >= buf_count) { @@ -844,7 +853,7 @@ int viewer_list_sessions(struct relay_connection *conn) new_buf_count * sizeof(*send_session_buf)); if (!newbuf) { ret = -1; - break; + goto break_loop; } send_session_buf = newbuf; buf_count = new_buf_count; @@ -854,12 +863,12 @@ int viewer_list_sessions(struct relay_connection *conn) session->session_name, sizeof(send_session->session_name))) { ret = -1; - break; + goto break_loop; } if (lttng_strncpy(send_session->hostname, session->hostname, sizeof(send_session->hostname))) { ret = -1; - break; + goto break_loop; } send_session->id = htobe64(session->id); send_session->live_timer = htobe32(session->live_timer); @@ -870,6 +879,12 @@ int viewer_list_sessions(struct relay_connection *conn) } send_session->streams = htobe32(session->stream_count); count++; + next_session: + pthread_mutex_unlock(&session->lock); + continue; + break_loop: + pthread_mutex_unlock(&session->lock); + break; } rcu_read_unlock(); if (ret < 0) { -- 2.34.1