Ver Fonte

Merge pull request #1751 from smallstep/herman/handle-server-startup-errors

Handle CA server startup errors
Herman Slatman há 2 anos atrás
pai
commit
a7a4b47ead
1 ficheiros alterados com 14 adições e 0 exclusões
  1. 14 0
      ca/ca.go

+ 14 - 0
ca/ca.go

@@ -476,6 +476,20 @@ func (ca *CA) Run() error {
 	// wait till error occurs; ensures the servers keep listening
 	err := <-errs
 
+	// if the error is not the usual HTTP server closed error, it is
+	// highly likely that an error occurred when starting one of the
+	// CA servers, possibly because of a port already being in use or
+	// some part of the configuration not being correct. This case is
+	// handled by stopping the CA in its entirety.
+	if !errors.Is(err, http.ErrServerClosed) {
+		log.Println("shutting down due to startup error ...")
+		if stopErr := ca.Stop(); stopErr != nil {
+			err = fmt.Errorf("failed stopping CA after error occurred: %w: %w", err, stopErr)
+		} else {
+			err = fmt.Errorf("stopped CA after error occurred: %w", err)
+		}
+	}
+
 	wg.Wait()
 
 	return err