Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

fix(master): stop goraft server on shutdown and bump raft to v1.2.1 (#11284)

Chris Luc46f82d29aab
diff --git a/go.mod b/go.mod
index cfdd31aa21..51b48b1b8b 100644
--- a/go.mod
+++ b/go.mod
@@ -65,7 +65,7 @@ require (
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/seaweedfs/goexif v2.0.0+incompatible
- github.com/seaweedfs/raft v1.2.0
+ github.com/seaweedfs/raft v1.2.1
github.com/sirupsen/logrus v1.9.4 // indirect
github.com/spf13/afero v1.15.0 // indirect
github.com/spf13/cast v1.10.0 // indirect
diff --git a/go.sum b/go.sum
index 3a160aca38..db812e3ba1 100644
--- a/go.sum
+++ b/go.sum
@@ -1821,8 +1821,8 @@ github.com/seaweedfs/go-fuse/v2 v2.9.4 h1:ACyloiuopdhRSjdLLeSWbsVaemMPskORaRF01T
github.com/seaweedfs/go-fuse/v2 v2.9.4/go.mod h1:zABdmWEa6A0bwaBeEOBUeUkGIZlxUhcdv+V1Dcc/U/I=
github.com/seaweedfs/goexif v2.0.0+incompatible h1:x8pckiT12QQhifwhDQpeISgDfsqmQ6VR4LFPQ64JRps=
github.com/seaweedfs/goexif v2.0.0+incompatible/go.mod h1:Oni780Z236sXpIQzk1XoJlTwqrJ02smEin9zQeff7Fk=
-github.com/seaweedfs/raft v1.2.0 h1:Ez4Hw9ifBbTT7wg54DvGHBjw1vRlTb4roH0TKl0Oj9Y=
-github.com/seaweedfs/raft v1.2.0/go.mod h1:fgs/rAVEzjQ7e04XMzG3eJhwZZRmBW+2uRtjakeCGeU=
+github.com/seaweedfs/raft v1.2.1 h1:QgFl/aaPnagpUxYB6Bx+fFss1NyetVVcJmraMmnaQ5Q=
+github.com/seaweedfs/raft v1.2.1/go.mod h1:fgs/rAVEzjQ7e04XMzG3eJhwZZRmBW+2uRtjakeCGeU=
github.com/secure-systems-lab/go-securesystemslib v0.11.0 h1:iuCR9kcMFD4QurdKrGvPLoKZLv9YvwPYVr0473BdtFs=
github.com/secure-systems-lab/go-securesystemslib v0.11.0/go.mod h1:+PMOTjUGwHj2vcZ+TFKlb1tXRbrdWE1LYDT5i9JC80Q=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
diff --git a/weed/server/master_server.go b/weed/server/master_server.go
index f31cbb4de7..3a1364c113 100644
--- a/weed/server/master_server.go
+++ b/weed/server/master_server.go
@@ -621,13 +621,27 @@ func (ms *MasterServer) missingRaftPeerName(peerAddress pb.ServerAddress) (strin
}
func (ms *MasterServer) Shutdown() {
- if ms.Topo == nil || ms.Topo.HashicorpRaft == nil {
+ if ms.Topo == nil {
return
}
- if ms.Topo.HashicorpRaft.State() == hashicorpRaft.Leader {
- ms.Topo.HashicorpRaft.LeadershipTransfer()
+ ms.Topo.RaftServerAccessLock.RLock()
+ raftServer := ms.Topo.RaftServer
+ hashRaft := ms.Topo.HashicorpRaft
+ ms.Topo.RaftServerAccessLock.RUnlock()
+
+ if hashRaft != nil {
+ if hashRaft.State() == hashicorpRaft.Leader {
+ hashRaft.LeadershipTransfer()
+ }
+ hashRaft.Shutdown()
+ }
+ // Stop the goraft server too. Without this, the raft event loop
+ // goroutine (leaderLoop/followerLoop) keeps running after the master
+ // shuts down, leaking goroutines across test runs and occasionally
+ // processing stale events that trigger safety assertions.
+ if raftServer != nil {
+ raftServer.Stop()
}
- ms.Topo.HashicorpRaft.Shutdown()
}
func (ms *MasterServer) Reload() {