From: David Goulet Date: Wed, 19 Dec 2012 20:36:59 +0000 (-0500) Subject: Fix: Off by one in seq num for data pending command X-Git-Tag: v2.1.0~15 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=39df6d9f42d8644d9ee25c8c02517b2cef6f5941;p=lttng-tools.git Fix: Off by one in seq num for data pending command Like the close stream command, the next sequence number of the stream needs to be used minus 1 for the data pending or else we are off by one on the relayd during the check since 4 data packets for instance means a prev_seq value of 4 but a last_next_seq_num of 5 hence creating an off by one for the data pending check. Furthermore, the check was actually wrong on the relayd side. Having a previous sequence number lower than the last one seen does NOT mean that the data is not pending so the check needed was actually equal or greater. Signed-off-by: David Goulet --- diff --git a/src/bin/lttng-relayd/main.c b/src/bin/lttng-relayd/main.c index 47780e266..d0cf15a30 100644 --- a/src/bin/lttng-relayd/main.c +++ b/src/bin/lttng-relayd/main.c @@ -1427,7 +1427,7 @@ int relay_data_pending(struct lttcomm_relayd_hdr *recv_hdr, last_net_seq_num); /* Avoid wrapping issue */ - if (((int64_t) (stream->prev_seq - last_net_seq_num)) <= 0) { + if (((int64_t) (stream->prev_seq - last_net_seq_num)) >= 0) { /* Data has in fact been written and is NOT pending */ ret = 0; } else { diff --git a/src/common/consumer.c b/src/common/consumer.c index be984a492..61d6f2e79 100644 --- a/src/common/consumer.c +++ b/src/common/consumer.c @@ -782,6 +782,13 @@ static int write_relayd_stream_header(struct lttng_consumer_stream *stream, data_hdr.stream_id = htobe64(stream->relayd_stream_id); data_hdr.data_size = htobe32(data_size); data_hdr.padding_size = htobe32(padding); + /* + * Note that net_seq_num below is assigned with the *current* value of + * next_net_seq_num and only after that the next_net_seq_num will be + * increment. This is why when issuing a command on the relayd using + * this next value, 1 should always be substracted in order to compare + * the last seen sequence number on the relayd side to the last sent. + */ data_hdr.net_seq_num = htobe64(stream->next_net_seq_num++); /* Other fields are zeroed previously */ @@ -3021,7 +3028,8 @@ int consumer_data_pending(uint64_t id) stream->relayd_stream_id); } else { ret = relayd_data_pending(&relayd->control_sock, - stream->relayd_stream_id, stream->next_net_seq_num); + stream->relayd_stream_id, + stream->next_net_seq_num - 1); } pthread_mutex_unlock(&relayd->ctrl_sock_mutex); if (ret == 1) {