From: Jérémie Galarneau Date: Wed, 2 Mar 2022 17:59:17 +0000 (-0500) Subject: Fix: relayd: connection abruptly closed on viewer stream creation failure X-Git-Tag: v2.13.5~20 X-Git-Url: https://git.liburcu.org/?p=lttng-tools.git;a=commitdiff_plain;h=4045de2805a4f5f980bbd0af9ca152aff4c691e3 Fix: relayd: connection abruptly closed on viewer stream creation failure Commit fe88e5175 explains (and fixes) an issue that could cause the creation of viewer streams to fail. Currently, the error path causes the relay daemon to abruptly close the connection to its live viewer peer. This behaviour makes it impossible for the viewer to determine if an error occurred or if the network connection simply failed. Returning an `LTTNG_VIEWER_NEW_STREAMS_ERR` status code allows the viewer to report a precise error. The viewer connection is closed since the internal error is unlikely to be recoverable. Signed-off-by: Jérémie Galarneau Change-Id: I557a8b66c1bd1c0bf361cfbabe962d8a6808f4f4 --- diff --git a/src/bin/lttng-relayd/live.c b/src/bin/lttng-relayd/live.c index 7a62059ee..f1e440640 100644 --- a/src/bin/lttng-relayd/live.c +++ b/src/bin/lttng-relayd/live.c @@ -1180,7 +1180,12 @@ int viewer_get_new_streams(struct relay_connection *conn) LTTNG_VIEWER_SEEK_BEGINNING, &nb_total, &nb_unsent, &nb_created, &closed); if (ret < 0) { - goto error_unlock_session; + /* + * This is caused by an internal error; propagate the negative + * 'ret' to close the connection. + */ + response.status = htobe32(LTTNG_VIEWER_NEW_STREAMS_ERR); + goto send_reply; } send_streams = 1; response.status = htobe32(LTTNG_VIEWER_NEW_STREAMS_OK); @@ -1235,10 +1240,6 @@ end_put_session: } error: return ret; -error_unlock_session: - pthread_mutex_unlock(&session->lock); - session_put(session); - return ret; } /*