Fix: relayd: live: crash on attach to a session without trace chunk
[lttng-tools.git] / src / bin / lttng-relayd / live.c
index 74c28a45784a1962aa9c068a63cccf9461f5a600..e480f86e483400874c2240b78dfe74b46524222f 100644 (file)
@@ -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) {
@@ -1065,6 +1080,15 @@ int viewer_attach_session(struct relay_connection *conn)
        DBG("Attach session ID %" PRIu64 " received", session_id);
 
        pthread_mutex_lock(&session->lock);
+       if (!session->current_trace_chunk) {
+               /*
+                * Session is either being destroyed or it never had a trace
+                * chunk created against it.
+                */
+               DBG("Session requested by live client has no current trace chunk, returning unknown session");
+               response.status = htobe32(LTTNG_VIEWER_ATTACH_UNK);
+               goto send_reply;
+       }
        if (session->live_timer == 0) {
                DBG("Not live session");
                response.status = htobe32(LTTNG_VIEWER_ATTACH_NOT_LIVE);
This page took 0.024286 seconds and 4 git commands to generate.