X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-relayd%2Flive.c;h=9a3d78ef0fc3a0632476d131202b325d77e17e82;hb=bf9f320b357536c881b3b7a81177e74062dfc673;hp=8c4f501aa3446afd5b5cb5d7e72e42bf82dd2d11;hpb=3c42c3ed6dcfd89b1a41074c01e4b21ab8c599ae;p=lttng-tools.git diff --git a/src/bin/lttng-relayd/live.c b/src/bin/lttng-relayd/live.c index 8c4f501aa..9a3d78ef0 100644 --- a/src/bin/lttng-relayd/live.c +++ b/src/bin/lttng-relayd/live.c @@ -954,15 +954,22 @@ int viewer_get_new_streams(struct relay_connection *conn) } if (!viewer_session_is_attached(conn->viewer_session, session)) { - send_streams = 0; response.status = htobe32(LTTNG_VIEWER_NEW_STREAMS_ERR); goto send_reply; } - send_streams = 1; - response.status = htobe32(LTTNG_VIEWER_NEW_STREAMS_OK); - pthread_mutex_lock(&session->lock); + if (!session->current_trace_chunk) { + /* + * Means the session is being destroyed. React the same way + * as if it could not be found at all. + */ + DBG("Relay session %" PRIu64 " has no current trace chunk, replying LTTNG_VIEWER_NEW_STREAMS_ERR", + session_id); + response.status = htobe32(LTTNG_VIEWER_NEW_STREAMS_ERR); + goto send_reply_unlock; + } + if (!conn->viewer_session->current_trace_chunk && session->current_trace_chunk) { ret = viewer_session_set_trace_chunk(conn->viewer_session, @@ -978,7 +985,8 @@ int viewer_get_new_streams(struct relay_connection *conn) if (ret < 0) { goto error_unlock_session; } - pthread_mutex_unlock(&session->lock); + send_streams = 1; + response.status = htobe32(LTTNG_VIEWER_NEW_STREAMS_OK); /* Only send back the newly created streams with the unsent ones. */ nb_streams = nb_created + nb_unsent; @@ -992,8 +1000,10 @@ int viewer_get_new_streams(struct relay_connection *conn) send_streams = 0; response.streams_count = 0; response.status = htobe32(LTTNG_VIEWER_NEW_STREAMS_HUP); - goto send_reply; + goto send_reply_unlock; } +send_reply_unlock: + pthread_mutex_unlock(&session->lock); send_reply: health_code_update(); @@ -1080,6 +1090,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);