-
Notifications
You must be signed in to change notification settings - Fork 526
Make gracefull exit of a node that is waiting for WaitForBlock call #679
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,9 +55,7 @@ type Server struct { | |
| node *node.AlgorandFullNode | ||
| metricCollector *metrics.MetricService | ||
| metricServiceStarted bool | ||
|
|
||
| stopping deadlock.Mutex | ||
| stopped bool | ||
| stopping chan struct{} | ||
| } | ||
|
|
||
| // Initialize creates a Node instance with applicable network services | ||
|
|
@@ -178,9 +176,11 @@ func (s *Server) Start() { | |
| os.Exit(1) | ||
| } | ||
|
|
||
| s.stopping = make(chan struct{}) | ||
|
|
||
| // use the data dir as the static file dir (for our API server), there's | ||
| // no need to separate the two yet. This lets us serve the swagger.json file. | ||
| apiHandler := apiServer.NewRouter(s.log, s.node, apiToken) | ||
| apiHandler := apiServer.NewRouter(s.log, s.node, s.stopping, apiToken) | ||
|
|
||
| addr := cfg.EndpointAddress | ||
| if addr == "" { | ||
|
|
@@ -202,8 +202,6 @@ func (s *Server) Start() { | |
| WriteTimeout: time.Duration(cfg.RestWriteTimeoutSeconds) * time.Second, | ||
| } | ||
|
|
||
| defer s.Stop() | ||
|
|
||
| tcpListener := listener.(*net.TCPListener) | ||
| errChan := make(chan error, 1) | ||
| go func() { | ||
|
|
@@ -227,30 +225,28 @@ func (s *Server) Start() { | |
| c := make(chan os.Signal) | ||
| signal.Notify(c, os.Interrupt, syscall.SIGTERM, syscall.SIGINT) | ||
| signal.Ignore(syscall.SIGHUP) | ||
| go func() { | ||
| sig := <-c | ||
|
|
||
| fmt.Printf("Node running and accepting RPC requests over HTTP on port %v. Press Ctrl-C to exit\n", addr) | ||
| select { | ||
| case err := <-errChan: | ||
| if err != nil { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. errChan name is giving the impression that only errors will trigger this case.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will look into that in a subsequent PR. |
||
| s.log.Warn(err) | ||
| } else { | ||
| s.log.Info("Node exited successfully") | ||
| } | ||
| s.Stop() | ||
| case sig := <-c: | ||
| fmt.Printf("Exiting on %v\n", sig) | ||
| s.Stop() | ||
| os.Exit(0) | ||
| }() | ||
|
|
||
| fmt.Printf("Node running and accepting RPC requests over HTTP on port %v. Press Ctrl-C to exit\n", addr) | ||
| err = <-errChan | ||
| if err != nil { | ||
| s.log.Warn(err) | ||
| } else { | ||
| s.log.Info("Node exited successfully") | ||
| } | ||
| } | ||
|
|
||
| // Stop initiates a graceful shutdown of the node by shutting down the network server. | ||
| func (s *Server) Stop() { | ||
| s.stopping.Lock() | ||
| defer s.stopping.Unlock() | ||
|
|
||
| if s.stopped { | ||
| return | ||
| } | ||
| // close the s.stopping, which would signal the rest api router that any pending commands | ||
| // should be aborted. | ||
| close(s.stopping) | ||
|
tsachiherman marked this conversation as resolved.
|
||
|
|
||
| // Attempt to log a shutdown event before we exit... | ||
| s.log.Event(telemetryspec.ApplicationState, telemetryspec.ShutdownEvent) | ||
|
|
@@ -275,8 +271,6 @@ func (s *Server) Stop() { | |
| os.Remove(s.pidFile) | ||
| os.Remove(s.netFile) | ||
| os.Remove(s.netListenFile) | ||
|
|
||
| s.stopped = true | ||
| } | ||
|
|
||
| // OverridePhonebook is used to replace the phonebook associated with | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.