mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-14 10:10:42 -07:00
Merge pull request #1276 from nats-io/fix_lame_duck_mode_shutdown
[FIXED] Server that is sent the lame duck mode signal does not exit
This commit is contained in:
3
main.go
3
main.go
@@ -17,7 +17,6 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime"
|
||||
|
||||
"github.com/nats-io/nats-server/v2/server"
|
||||
)
|
||||
@@ -110,5 +109,5 @@ func main() {
|
||||
if err := server.Run(s); err != nil {
|
||||
server.PrintAndDie(err.Error())
|
||||
}
|
||||
runtime.Goexit()
|
||||
s.WaitForShutdown()
|
||||
}
|
||||
|
||||
@@ -139,7 +139,8 @@ type Server struct {
|
||||
dialTimeout time.Duration
|
||||
}
|
||||
|
||||
quitCh chan struct{}
|
||||
quitCh chan struct{}
|
||||
shutdownComplete chan struct{}
|
||||
|
||||
// Tracking Go routines
|
||||
grMu sync.Mutex
|
||||
@@ -323,6 +324,9 @@ func NewServer(opts *Options) (*Server, error) {
|
||||
// Used to kick out all go routines possibly waiting on server
|
||||
// to shutdown.
|
||||
s.quitCh = make(chan struct{})
|
||||
// Closed when Shutdown() is complete. Allows WaitForShutdown() to block
|
||||
// waiting for complete shutdown.
|
||||
s.shutdownComplete = make(chan struct{})
|
||||
|
||||
// For tracking accounts
|
||||
if err := s.configureAccounts(); err != nil {
|
||||
@@ -1334,6 +1338,13 @@ func (s *Server) Shutdown() {
|
||||
l.Close()
|
||||
}
|
||||
}
|
||||
// Notify that the shutdown is complete
|
||||
close(s.shutdownComplete)
|
||||
}
|
||||
|
||||
// WaitForShutdown will block until the server has been fully shutdown.
|
||||
func (s *Server) WaitForShutdown() {
|
||||
<-s.shutdownComplete
|
||||
}
|
||||
|
||||
// AcceptLoop is exported for easier testing.
|
||||
|
||||
Reference in New Issue
Block a user