Merge pull request #160 from StephenButtolph/require-http-port

Exit the node if the http server errors
This commit is contained in:
Stephen Buttolph 2020-05-13 13:56:57 -04:00 committed by GitHub
commit f290f7377e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 15 deletions

View File

@ -479,18 +479,19 @@ func (n *Node) initAPIServer() {
n.APIServer.Initialize(n.Log, n.LogFactory, n.Config.HTTPPort)
if n.Config.EnableHTTPS {
n.Log.Debug("Initializing API server with TLS Enabled")
go n.Log.RecoverAndPanic(func() {
if err := n.APIServer.DispatchTLS(n.Config.HTTPSCertFile, n.Config.HTTPSKeyFile); err != nil {
n.Log.Warn("API server initialization failed with %s, attempting to create insecure API server", err)
n.APIServer.Dispatch()
}
})
} else {
n.Log.Debug("Initializing API server with TLS Disabled")
go n.Log.RecoverAndPanic(func() { n.APIServer.Dispatch() })
}
go n.Log.RecoverAndPanic(func() {
if n.Config.EnableHTTPS {
n.Log.Debug("Initializing API server with TLS Enabled")
err := n.APIServer.DispatchTLS(n.Config.HTTPSCertFile, n.Config.HTTPSKeyFile)
n.Log.Warn("Secure API server initialization failed with %s, attempting to create insecure API server", err)
}
n.Log.Debug("Initializing API server")
err := n.APIServer.Dispatch()
n.Log.Fatal("API server initialization failed with %s", err)
n.TCall.AsyncCall(salticidae.ThreadCallCallback(C.onTerm), nil)
})
}
// Assumes n.DB, n.vdrs all initialized (non-nil)
@ -623,15 +624,16 @@ func (n *Node) Initialize(Config *Config, logger logging.Logger, logFactory logg
// initialize shared memory
n.initSharedMemory()
if err = n.initNetlib(); err != nil { // Set up all networking
return fmt.Errorf("problem initializing networking: %w", err)
}
// Start HTTP APIs
n.initAPIServer() // Start the API Server
n.initKeystoreAPI() // Start the Keystore API
n.initMetricsAPI() // Start the Metrics API
// Start node-to-node consensus server
if err = n.initNetlib(); err != nil { // Set up all networking
return fmt.Errorf("problem initializing networking: %w", err)
}
if err := n.initValidatorNet(); err != nil { // Set up the validator handshake + authentication
return fmt.Errorf("problem initializing validator network: %w", err)
}