Fix: relayd: live: invalid return code on DETACH_SESSION
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 9 Oct 2020 16:04:10 +0000 (12:04 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 9 Oct 2020 21:03:08 +0000 (17:03 -0400)
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 <jeremie.galarneau@efficios.com>
Change-Id: I69ed74f83404a16353d2bdbaa9f3adcdc2a03892

src/bin/lttng-relayd/live.c

index 7d6dc1bc20a03a5af6cafe1e5ef170be1b7f5cb8..ccba8d70594c278aaabfee2a6d4b6687cd0adc34 100644 (file)
@@ -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:
This page took 0.026033 seconds and 4 git commands to generate.