diff --git a/kong/cmd/utils/serf_signals.lua b/kong/cmd/utils/serf_signals.lua index aace0cf5cf1..cadf646a464 100644 --- a/kong/cmd/utils/serf_signals.lua +++ b/kong/cmd/utils/serf_signals.lua @@ -92,6 +92,10 @@ function _M.start(kong_config, dao) return nil, "could not start Serf: "..err end + -- cleanup current node from cluster to prevent inconsistency of data + local ok, err = serf:cleanup() + if not ok then return nil, err end + log.verbose("auto-joining Serf cluster...") local ok, err = serf:autojoin() if not ok then return nil, err end diff --git a/kong/serf.lua b/kong/serf.lua index 8af9b4c73fe..b684a5efee2 100644 --- a/kong/serf.lua +++ b/kong/serf.lua @@ -80,12 +80,14 @@ function Serf:reachability() return self:invoke_signal("reachability") end -function Serf:autojoin() +function Serf:cleanup() -- Delete current node just in case it was there -- (due to an inconsistency caused by a crash) - local _, err = self.dao.nodes:delete {name = self.node_name} - if err then return nil, tostring(err) end + local ok, err = self.dao.nodes:delete {name = self.node_name } + return ok, tostring(err) +end +function Serf:autojoin() local nodes, err = self.dao.nodes:find_all() if err then return nil, tostring(err) elseif #nodes == 0 then