diff --git a/server/events.go b/server/events.go index 9da504f713..2d8283e89e 100644 --- a/server/events.go +++ b/server/events.go @@ -56,6 +56,7 @@ const ( connsRespSubj = "$SYS._INBOX_.%s" accConnsEventSubjNew = "$SYS.ACCOUNT.%s.SERVER.CONNS" accConnsEventSubjOld = "$SYS.SERVER.ACCOUNT.%s.CONNS" // kept for backward compatibility + lameDuckEventSubj = "$SYS.SERVER.%s.LAMEDUCK" shutdownEventSubj = "$SYS.SERVER.%s.SHUTDOWN" authErrorEventSubj = "$SYS.SERVER.%s.CLIENT.AUTH.ERR" serverStatsSubj = "$SYS.SERVER.%s.STATSZ" @@ -541,7 +542,7 @@ func (s *Server) sendLDMShutdownEventLocked() { if s.sys == nil || s.sys.sendq == nil { return } - subj := fmt.Sprintf(shutdownEventSubj, s.info.ID) + subj := fmt.Sprintf(lameDuckEventSubj, s.info.ID) si := &ServerInfo{} s.sys.sendq.push(newPubMsg(nil, subj, _EMPTY_, si, nil, si, noCompression, false, true)) } @@ -957,6 +958,13 @@ func (s *Server) initEventTracking() { if _, err := s.sysSubscribe(subject, s.noInlineCallback(s.remoteServerShutdown)); err != nil { s.Errorf("Error setting up internal tracking: %v", err) } + // Listen for servers entering lame-duck mode. + // NOTE: This currently is handled in the same way as a server shutdown, but has + // a different subject in case we need to handle differently in future. + subject = fmt.Sprintf(lameDuckEventSubj, "*") + if _, err := s.sysSubscribe(subject, s.noInlineCallback(s.remoteServerShutdown)); err != nil { + s.Errorf("Error setting up internal tracking: %v", err) + } // Listen for account claims updates. subscribeToUpdate := true if s.accResolver != nil { diff --git a/server/events_test.go b/server/events_test.go index 5398bedad2..34a9d0d473 100644 --- a/server/events_test.go +++ b/server/events_test.go @@ -1666,7 +1666,7 @@ func TestSystemAccountWithGateways(t *testing.T) { // If this tests fails with wrong number after 10 seconds we may have // added a new inititial subscription for the eventing system. - checkExpectedSubs(t, 45, sa) + checkExpectedSubs(t, 46, sa) // Create a client on B and see if we receive the event urlb := fmt.Sprintf("nats://%s:%d", ob.Host, ob.Port) diff --git a/server/monitor_test.go b/server/monitor_test.go index a0caa5794d..c98429cbbc 100644 --- a/server/monitor_test.go +++ b/server/monitor_test.go @@ -3942,7 +3942,7 @@ func TestMonitorAccountz(t *testing.T) { body = string(readBody(t, fmt.Sprintf("http://127.0.0.1:%d%s?acc=$SYS", s.MonitorAddr().Port, AccountzPath))) require_Contains(t, body, `"account_detail": {`) require_Contains(t, body, `"account_name": "$SYS",`) - require_Contains(t, body, `"subscriptions": 40,`) + require_Contains(t, body, `"subscriptions": 41,`) require_Contains(t, body, `"is_system": true,`) require_Contains(t, body, `"system_account": "$SYS"`)