From 3ee19e9a27e3d022ce63640d0a9912af2e1c4604 Mon Sep 17 00:00:00 2001 From: Ivan Kripakov Date: Wed, 20 Dec 2023 16:59:58 +0400 Subject: [PATCH] don't remove itself if node is a raft leader --- Makefile | 2 +- dkron/leader.go | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 45ba3e438..8f352faa9 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ release: -e DOCKER_USERNAME \ -e DOCKER_PASSWORD \ -e DOCKER_REGISTRY \ - -e GORELEASER_CURRENT_TAG=v3.2.7-M3 \ + -e GORELEASER_CURRENT_TAG=v3.2.7-M4 \ -v /var/run/docker.sock:/var/run/docker.sock \ goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \ release --rm-dist --skip-validate --timeout=1h diff --git a/dkron/leader.go b/dkron/leader.go index 1605cbe6e..27d169f57 100644 --- a/dkron/leader.go +++ b/dkron/leader.go @@ -3,6 +3,7 @@ package dkron import ( "fmt" "net" + "strings" "sync" "time" @@ -315,6 +316,15 @@ func (a *Agent) addRaftPeer(m serf.Member, parts *ServerParts) error { // removeRaftPeer is used to remove a Raft peer when a dkron server leaves // or is reaped func (a *Agent) removeRaftPeer(m serf.Member, parts *ServerParts) error { + + // Do not remove ourself. This can only happen if the current leader + // is leaving. Instead, we should allow a follower to take-over and + // deregister us later. + if strings.EqualFold(m.Name, a.config.NodeName) { + a.logger.Warn("removing self should be done by follower", "name", a.config.NodeName) + return nil + } + // See if it's already in the configuration. It's harmless to re-remove it // but we want to avoid doing that if possible to prevent useless Raft // log entries.