Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In lameduck mode shutdown jetstream at start, do not leave running #4579

Merged
merged 2 commits into from Sep 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions server/jetstream_cluster_3_test.go
Expand Up @@ -3472,13 +3472,13 @@ func TestJetStreamClusterNoR1AssetsDuringLameDuck(t *testing.T) {

// Make sure we do not have any R1 assets placed on the lameduck server.
for s.isRunning() {
s.rnMu.RLock()
s.mu.RLock()
if s.js == nil || s.js.srv == nil || s.js.srv.gacc == nil {
s.rnMu.RUnlock()
s.mu.RUnlock()
break
}
hasAsset := len(s.js.srv.gacc.streams()) > 0
s.rnMu.RUnlock()
s.mu.RUnlock()
if hasAsset {
t.Fatalf("Server had an R1 asset when it should not due to lameduck mode")
}
Expand Down
9 changes: 5 additions & 4 deletions server/raft.go
Expand Up @@ -588,14 +588,15 @@ func (s *Server) stepdownRaftNodes() {
s.Debugf("Stepping down all leader raft nodes")
}
for _, n := range s.raftNodes {
if n.Leader() {
nodes = append(nodes, n)
}
nodes = append(nodes, n)
}
s.rnMu.RUnlock()

for _, node := range nodes {
node.StepDown()
if node.Leader() {
node.StepDown()
}
node.SetObserver(true)
}
}

Expand Down
11 changes: 9 additions & 2 deletions server/server.go
Expand Up @@ -2380,7 +2380,7 @@ func (s *Server) Shutdown() {
accRes.Close()
}

// Now check jetstream.
// Now check and shutdown jetstream.
s.shutdownJetStream()

// Now shutdown the nodes
Expand Down Expand Up @@ -3944,7 +3944,8 @@ func (s *Server) isLameDuckMode() bool {
}

// This function will close the client listener then close the clients
// at some interval to avoid a reconnecting storm.
// at some interval to avoid a reconnect storm.
// We will also transfer any raft leaders and shutdown JetStream.
func (s *Server) lameDuckMode() {
s.mu.Lock()
// Check if there is actually anything to do
Expand Down Expand Up @@ -3985,6 +3986,12 @@ func (s *Server) lameDuckMode() {
}
}

// Now check and shutdown jetstream.
s.shutdownJetStream()

// Now shutdown the nodes
s.shutdownRaftNodes()

// Wait for accept loops to be done to make sure that no new
// client can connect
for i := 0; i < expected; i++ {
Expand Down