From 603bea2481917041e502952e834ccc53ddc876f0 Mon Sep 17 00:00:00 2001 From: JianBo He Date: Thu, 25 Jan 2024 13:53:06 +0800 Subject: [PATCH] fix(membership): leader calculation error in some cases For example, if a node has just joined the cluster, but has not fully rebooted successfully, its `guid` is undefined: ``` [{member,'emqx@10.42.3.236',undefined, <<0,6,15,187,202,198,177,159,90,134,0,0,11,232, 0,0>>, 3792610979,up,running, {1706,149095,584199}, core}, {member,'emqx@10.42.6.225',undefined,undefined, undefined,up,running, {1706,155167,852643}, core}] ``` --- src/mria_membership.erl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/mria_membership.erl b/src/mria_membership.erl index 1eac636..54d1514 100644 --- a/src/mria_membership.erl +++ b/src/mria_membership.erl @@ -183,6 +183,10 @@ oldest(Members) -> hd(lists:sort(fun compare/2, Members)). %% @private +compare(#member{guid = undefined}, #member{guid = _}) -> + false; +compare(#member{guid = _}, #member{guid = undefined}) -> + true; compare(M1, M2) -> M1#member.guid < M2#member.guid.