Skip to content

Commit

Permalink
Fix for #4789 to allow a restart of a shutdown server instance.
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Collison <derek@nats.io>
  • Loading branch information
derekcollison committed Nov 13, 2023
1 parent 108f76c commit 74805e9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
10 changes: 9 additions & 1 deletion server/server.go
Expand Up @@ -2083,6 +2083,11 @@ func (s *Server) Start() {

defer s.Noticef("Server is ready")

// Check is this may be a restart.
if s.startupComplete == nil {
s.startupComplete = make(chan struct{})
}

// Check for insecure configurations.
s.checkAuthforWarnings()

Expand Down Expand Up @@ -2340,7 +2345,10 @@ func (s *Server) Start() {
}

// We've finished starting up.
close(s.startupComplete)
if s.startupComplete != nil {
close(s.startupComplete)
s.startupComplete = nil
}

// Wait for clients.
if !opts.DontListen {
Expand Down
11 changes: 11 additions & 0 deletions server/server_test.go
Expand Up @@ -2107,3 +2107,14 @@ func TestServerAuthBlockAndSysAccounts(t *testing.T) {
_, err = nats.Connect(s.ClientURL())
require_Error(t, err, nats.ErrAuthorization, errors.New("nats: Authorization Violation"))
}

// https://github.com/nats-io/nats-server/issues/4789
func TestServerRestartAfterShutdown(t *testing.T) {
opts := DefaultTestOptions
opts.Port = -1
s := RunServer(&opts)
s.Shutdown()
s.WaitForShutdown()
s.Start()
defer s.Shutdown()
}

0 comments on commit 74805e9

Please sign in to comment.