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
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: