Skip to content

Commit

Permalink
In lameduck mode shutdown jetstream at start, do not leave running (#…
Browse files Browse the repository at this point in the history
…4579)

Signed-off-by: Derek Collison <derek@nats.io>
  • Loading branch information
derekcollison committed Sep 24, 2023
2 parents fe2c116 + 121adb4 commit 30af2a4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion server/consumer.go
Expand Up @@ -1564,7 +1564,7 @@ func (o *consumer) deleteNotActive() {
// Don't think this needs to be a monitored go routine.
go func() {
const (
startInterval = 5 * time.Second
startInterval = 30 * time.Second
maxInterval = 5 * time.Minute
)
jitter := time.Duration(rand.Int63n(int64(startInterval)))
Expand Down
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

0 comments on commit 30af2a4

Please sign in to comment.