Fix: relayd reply error to client if cannot find viewer stream
[lttng-tools.git] / src / bin / lttng-relayd / live.c
index 888ec2d4f616d10f5d4720bfbea05158361d48bf..c5a6e4edd8450e2048e955b4abd6ca8219f59fe1 100644 (file)
@@ -1273,8 +1273,8 @@ int viewer_get_next_index(struct relay_connection *conn)
 
        vstream = viewer_stream_get_by_id(be64toh(request_index.stream_id));
        if (!vstream) {
-               ret = -1;
-               goto end;
+               viewer_index.status = htobe32(LTTNG_VIEWER_INDEX_ERR);
+               goto send_reply;
        }
 
        /* Use back. ref. Protected by refcounts. */
@@ -1397,7 +1397,9 @@ int viewer_get_next_index(struct relay_connection *conn)
        viewer_index.stream_id = packet_index.stream_id;
 
 send_reply:
-       pthread_mutex_unlock(&rstream->lock);
+       if (rstream) {
+               pthread_mutex_unlock(&rstream->lock);
+       }
 
        if (metadata_viewer_stream) {
                pthread_mutex_lock(&metadata_viewer_stream->stream->lock);
@@ -1629,7 +1631,15 @@ int viewer_get_metadata(struct relay_connection *conn)
 
        vstream = viewer_stream_get_by_id(be64toh(request.stream_id));
        if (!vstream) {
-               reply.status = htobe32(LTTNG_VIEWER_NO_NEW_METADATA);
+               /*
+                * The metadata stream can be closed by a CLOSE command
+                * just before we attach. It can also be closed by
+                * per-pid tracing during tracing. Therefore, it is
+                * possible that we cannot find this viewer stream.
+                * Reply back to the client with an error if we cannot
+                * find it.
+                */
+               reply.status = htobe32(LTTNG_VIEWER_METADATA_ERR);
                goto send_reply;
        }
        pthread_mutex_lock(&vstream->stream->lock);
This page took 0.039402 seconds and 5 git commands to generate.