Merge pull request #799 from nats-io/update_lame_duck_mode

Introduce some delay before closing clients in LameDuck mode.
This commit is contained in:
Ivan Kozlovic
2018-11-08 19:46:19 -07:00
committed by GitHub
3 changed files with 72 additions and 3 deletions

View File

@@ -38,6 +38,12 @@ import (
"github.com/nats-io/gnatsd/logger"
)
// Time to wait before starting closing clients when in LD mode.
const lameDuckModeDefaultInitialDelay = int64(time.Second)
// Make this a variable so that we can change during tests
var lameDuckModeInitialDelay = int64(lameDuckModeDefaultInitialDelay)
// Info is the information sent to clients to help them understand information
// about this server.
type Info struct {
@@ -1626,8 +1632,16 @@ func (s *Server) lameDuckMode() {
}
s.mu.Unlock()
t := time.NewTimer(10 * time.Second)
s.Noticef("Closing existing clients")
t := time.NewTimer(time.Duration(atomic.LoadInt64(&lameDuckModeInitialDelay)))
// Delay start of closing of client connections in case
// we have several servers that we want to signal to enter LD mode
// and not have their client reconnect to each other.
select {
case <-t.C:
s.Noticef("Closing existing clients")
case <-s.quitCh:
return
}
for i, client := range clients {
client.closeConnection(ServerShutdown)
if batch == 1 || i%batch == 0 {