From: Jérémie Galarneau Date: Wed, 6 Apr 2022 19:48:31 +0000 (-0400) Subject: Fix: notification: assert on len > 0 for dropped notification message X-Git-Tag: v2.12.11~1 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=4301861c0b2acc18c48287d9c022aaee3a487024;p=lttng-tools.git Fix: notification: assert on len > 0 for dropped notification message Observed issue ============== Using the notification client from doc/examples/trigger-condition-event-matches/notification-client.cpp, an assert is hit when the notification subsystem is under load. #0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50 #1 0x00007f69eab58859 in __GI_abort () at abort.c:79 #2 0x00007f69eab58729 in __assert_fail_base (fmt=0x7f69eacee588 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x7f69eae1d5dd "len > 0", file=0x7f69eae1d5cb "unix.cpp", line=179, function=) at assert.c:92 #3 0x00007f69eab6a006 in __GI___assert_fail (assertion=0x7f69eae1d5dd "len > 0", file=0x7f69eae1d5cb "unix.cpp", line=179, function=0x7f69eae1d598 "ssize_t lttcomm_recv_unix_sock(int, void*, size_t)") at assert.c:101 #4 0x00007f69eadd5fe6 in lttcomm_recv_unix_sock (sock=3, buf=0x55da9ecd5f89, len=0) at unix.cpp:179 #5 0x00007f69ead7df3f in receive_message (channel=0x55da9ecd6ee0) at channel.cpp:64 #6 0x00007f69ead7e478 in lttng_notification_channel_get_next_notification (channel=0x55da9ecd6ee0, _notification=0x7ffdefed2570) at channel.cpp:279 #7 0x000055da9e0e742f in main (argc=2, argv=0x7ffdefed2698) at notification-client.cpp:506 (gdb) frame #5 0x00007f69ead7df3f in receive_message (channel=0x55da9ecd6ee0) at channel.cpp:64 64 ret = lttcomm_recv_unix_sock(channel->socket, (gdb) print msg $2 = {type = 5 '\005', size = 0, fds = 0, payload = 0x7ffdefed24a8 ""} The msg type 5 is `LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_NOTIFICATION_DROPPED` Cause ===== The msg portion of a `LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_NOTIFICATION_DROPPED` is indeed zero. There is no extra payload. Solution ======== When the msg size is zero, skip the 'payload' reception phase. Known drawbacks ========= None. Signed-off-by: Jonathan Rajotte Signed-off-by: Jérémie Galarneau Change-Id: Ibabb922d0e410c9902414a5eabbe04738861d772 --- diff --git a/src/lib/lttng-ctl/channel.c b/src/lib/lttng-ctl/channel.c index 882fb7be4..44d86a357 100644 --- a/src/lib/lttng-ctl/channel.c +++ b/src/lib/lttng-ctl/channel.c @@ -54,6 +54,10 @@ int receive_message(struct lttng_notification_channel *channel) goto error; } + if (msg.size == 0) { + goto skip_payload; + } + /* Reserve space for the payload. */ ret = lttng_dynamic_buffer_set_size(&channel->reception_buffer, channel->reception_buffer.size + msg.size); @@ -68,6 +72,8 @@ int receive_message(struct lttng_notification_channel *channel) ret = -1; goto error; } + +skip_payload: ret = 0; end: return ret;