Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIXED] #4789 to allow a restart of a shutdown server instance. #4792

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion server/server.go
Original file line number Diff line number Diff line change
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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think one should ask if we want to support calling s.Start() after a s.Shutdown(). If yes, then I think it is a bit more than that, that needs to be done. I believe that there are others things that are created/setup in NewServer() whose state may be changed during Shutdown() and that Start() will not take into account.

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
Original file line number Diff line number Diff line change
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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Case in point, would s.Shutdown() not panic because channel shutdownComplete has already been closed in previous Shutdown()? My point is that I believe that there way more state that would need to be recreated/reset on a Start() after a Shutdown() that we can think of.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it does not panic, it means that the second Shutdown() is actually not shutting down, likely because the code thinks it is already shutdown...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meaning we should expand the test to make sure the server is usable? Or are you suggesting that the second start should fail and you can not re-use servers that have been shutdown?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latter. I think that there is a lot of "state" that would need to be recreated/reset if we wanted to support a Start() after a Shutdown() (and therefore subsequent Shutdown() calls..). The only issue I have with that is Start() does not return an error, so that would leave the user not knowing that it is not started again. We could add a StartServer() or something like that, that would return an error (similar to what we did with NewServer vs New).

}
Loading