mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-17 11:24:44 -07:00
Re-add startupComplete channel, make readyForConnections wait for it
This commit is contained in:
@@ -167,6 +167,7 @@ type Server struct {
|
||||
leafNodeEnabled bool
|
||||
|
||||
quitCh chan struct{}
|
||||
startupComplete chan struct{}
|
||||
shutdownComplete chan struct{}
|
||||
|
||||
// Tracking Go routines
|
||||
@@ -499,6 +500,11 @@ 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 startup is complete. ReadyForConnections() will block on
|
||||
// this before checking the presence of listening sockets.
|
||||
s.startupComplete = make(chan struct{})
|
||||
|
||||
// Closed when Shutdown() is complete. Allows WaitForShutdown() to block
|
||||
// waiting for complete shutdown.
|
||||
s.shutdownComplete = make(chan struct{})
|
||||
@@ -1848,6 +1854,9 @@ func (s *Server) Start() {
|
||||
s.startGoRoutine(s.logRejectedTLSConns)
|
||||
}
|
||||
|
||||
// We've finished starting up.
|
||||
close(s.startupComplete)
|
||||
|
||||
// Wait for clients.
|
||||
if !opts.DontListen {
|
||||
s.AcceptLoop(clientListenReady)
|
||||
@@ -2939,6 +2948,17 @@ func (s *Server) ProfilerAddr() *net.TCPAddr {
|
||||
}
|
||||
|
||||
func (s *Server) readyForConnections(d time.Duration) error {
|
||||
// Wait for startup. At this point AcceptLoop will only just be
|
||||
// starting, so we'll still check for the presence of listeners
|
||||
// after this.
|
||||
select {
|
||||
case <-s.startupComplete:
|
||||
case <-time.After(d):
|
||||
return fmt.Errorf(
|
||||
"failed to be ready for connections after %s", d,
|
||||
)
|
||||
}
|
||||
|
||||
// Snapshot server options.
|
||||
opts := s.getOpts()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user