Tarantool development patches archive
 help / color / mirror / Atom feed
From: Serge Petrenko <sergepetrenko@tarantool.org>
To: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>,
	tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH 5/8] raft: fix crash when received 0 term message
Date: Wed, 16 Dec 2020 16:05:33 +0300	[thread overview]
Message-ID: <5e5f8b7f-3d48-b59e-627e-05dedc769490@tarantool.org> (raw)
In-Reply-To: <8178e04ab747795298ad57bc33d0b28392b291fe.1607879643.git.v.shpilevoy@tarantool.org>


13.12.2020 20:15, Vladislav Shpilevoy пишет:
> Term in raft can never be 0. It starts from 1 and can only grow.
> It was assumed it can't be received from other nodes because they
> do the same. There was an assertion for that.
>
> But in raft_msg, used as a transport unit between raft nodes, it
> was still possible to send 0 term. It could happen as a result of
> a bug, or if someone would try to mimic the protocol but made a
> mistake.
>
> That led to a crash in the assert in debug build.
>
> Part of #5303
> ---


Thanks for  the patch!

LGTM.


>   src/lib/raft/raft.c   | 1 -
>   test/unit/raft.c      | 8 +++++++-
>   test/unit/raft.result | 3 ++-
>   3 files changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/src/lib/raft/raft.c b/src/lib/raft/raft.c
> index 4d07d37e5..df34d81dc 100644
> --- a/src/lib/raft/raft.c
> +++ b/src/lib/raft/raft.c
> @@ -241,7 +241,6 @@ raft_sm_become_candidate(struct raft *raft);
>   static const char *
>   raft_msg_to_string(const struct raft_msg *req)
>   {
> -	assert(req->term != 0);
>   	char buf[1024];
>   	int size = sizeof(buf);
>   	char *pos = buf;
> diff --git a/test/unit/raft.c b/test/unit/raft.c
> index dfb5f8e43..1ed8b7af7 100644
> --- a/test/unit/raft.c
> +++ b/test/unit/raft.c
> @@ -247,7 +247,7 @@ raft_test_recovery(void)
>   static void
>   raft_test_bad_msg(void)
>   {
> -	raft_start_test(6);
> +	raft_start_test(7);
>   	struct raft_msg msg;
>   	struct raft_node node;
>   	struct vclock vclock;
> @@ -280,6 +280,12 @@ raft_test_bad_msg(void)
>   	   "candidate without vclock");
>   	is(node.raft.term, 1, "term from the bad message wasn't used");
>   
> +	msg = (struct raft_msg){
> +		.state = RAFT_STATE_FOLLOWER,
> +		.term = 0,
> +	};
> +	is(raft_node_process_msg(&node, &msg, 2), -1, "term can't be 0");
> +
>   	raft_node_destroy(&node);
>   	raft_finish_test();
>   }
> diff --git a/test/unit/raft.result b/test/unit/raft.result
> index a63515ed3..2398bd71c 100644
> --- a/test/unit/raft.result
> +++ b/test/unit/raft.result
> @@ -45,13 +45,14 @@ ok 1 - subtests
>   ok 2 - subtests
>   	*** raft_test_recovery: done ***
>   	*** raft_test_bad_msg ***
> -    1..6
> +    1..7
>       ok 1 - state can't be 0
>       ok 2 - term from the bad message wasn't used
>       ok 3 - node can't be a candidate but vote for another node
>       ok 4 - term from the bad message wasn't used
>       ok 5 - node can't be a candidate without vclock
>       ok 6 - term from the bad message wasn't used
> +    ok 7 - term can't be 0
>   ok 3 - subtests
>   	*** raft_test_bad_msg: done ***
>   	*** raft_test_vote ***

-- 
Serge Petrenko

  reply	other threads:[~2020-12-16 13:05 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-13 17:15 [Tarantool-patches] [PATCH 0/8] Raft module, part 4 - unit tests Vladislav Shpilevoy
2020-12-13 17:15 ` [Tarantool-patches] [PATCH 1/8] fakesys: fix ev_is_active not working on fake timers Vladislav Shpilevoy
2020-12-15  9:42   ` Serge Petrenko
2020-12-13 17:15 ` [Tarantool-patches] [PATCH 2/8] fakesys: introduce fakeev_timer_remaining() Vladislav Shpilevoy
2020-12-15  9:43   ` Serge Petrenko
2020-12-13 17:15 ` [Tarantool-patches] [PATCH 3/8] raft: introduce raft_ev Vladislav Shpilevoy
2020-12-15 10:02   ` Serge Petrenko
2020-12-13 17:15 ` [Tarantool-patches] [PATCH 4/8] test: introduce raft unit tests Vladislav Shpilevoy
2020-12-13 18:10   ` Vladislav Shpilevoy
2020-12-16 13:03   ` Serge Petrenko
2020-12-17 22:44     ` Vladislav Shpilevoy
2020-12-18  8:17       ` Serge Petrenko
2020-12-20 17:28         ` Vladislav Shpilevoy
2020-12-21  7:36           ` Serge Petrenko
2020-12-13 17:15 ` [Tarantool-patches] [PATCH 5/8] raft: fix crash when received 0 term message Vladislav Shpilevoy
2020-12-16 13:05   ` Serge Petrenko [this message]
2020-12-13 17:15 ` [Tarantool-patches] [PATCH 6/8] raft: fix ignorance of bad state receipt Vladislav Shpilevoy
2020-12-16 13:06   ` Serge Petrenko
2020-12-13 17:15 ` [Tarantool-patches] [PATCH 7/8] raft: fix crash on election timeout decrease Vladislav Shpilevoy
2020-12-16 13:08   ` Serge Petrenko
2020-12-13 17:15 ` [Tarantool-patches] [PATCH 8/8] raft: fix crash on death " Vladislav Shpilevoy
2020-12-16 13:10   ` Serge Petrenko
2020-12-21 16:50 ` [Tarantool-patches] [PATCH 0/8] Raft module, part 4 - unit tests Vladislav Shpilevoy
2020-12-21 17:29 ` Vladislav Shpilevoy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5e5f8b7f-3d48-b59e-627e-05dedc769490@tarantool.org \
    --to=sergepetrenko@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH 5/8] raft: fix crash when received 0 term message' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox