From: Jérémie Galarneau Date: Fri, 9 Oct 2020 16:04:10 +0000 (-0400) Subject: Fix: relayd: live: invalid return code on DETACH_SESSION X-Git-Tag: v2.13.0-rc1~465 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=f28ecb10121fd234be3cc473196ae058bc5a7ca7;p=lttng-tools.git Fix: relayd: live: invalid return code on DETACH_SESSION Babeltrace 2 reports an invalid return code being returned in reply to a DETACH_SESSION command. Reviewing the relevant Babeltrace 2 code, the logging can only be produced if the reception of the lttng_viewer_detach_session_response structure succeeds. This elemininated my first guess that this was caused by the relay daemon closing the socket before sending the reply. In that case, an invalid status code of '0' could have been erroneously returned as a status code since the recv() call on the socket would return 0. It turns out that on a failure to return a packet, viewer_get_packet() returns an error status code, but also sends a zero-initialized payload buffer of the size of the requested packet. This causes live clients which detach following the error of the GET_PACKET command to interpret the still-enqueued zero-initialized buffer as a reply to the DETACH_SESSION command. Since zero is not a valid status code, it is correctly interpreted as a protocol error. The reply_size is set to the header's size to only transmit the header when an error reply is sent. Signed-off-by: Jérémie Galarneau Change-Id: I69ed74f83404a16353d2bdbaa9f3adcdc2a03892 --- diff --git a/src/bin/lttng-relayd/live.c b/src/bin/lttng-relayd/live.c index 7d6dc1bc2..ccba8d705 100644 --- a/src/bin/lttng-relayd/live.c +++ b/src/bin/lttng-relayd/live.c @@ -1854,6 +1854,8 @@ int viewer_get_packet(struct relay_connection *conn) goto send_reply; error: + /* No payload to send on error. */ + reply_size = sizeof(reply_header); reply_header.status = htobe32(LTTNG_VIEWER_GET_PACKET_ERR); send_reply: