From 947dc96b30c221167526c5cd50ee45394eb6422c Mon Sep 17 00:00:00 2001 From: Chris Marchesi Date: Mon, 2 Aug 2021 09:35:57 -0700 Subject: [PATCH] server: Add back controller shutdown on worker startup failure (#1432) * server: Add back controller shutdown on worker startup failure This adds back the controller shutdown call on worker failure. This was added in a15961e4 to address a panic discovered in testing, and was mistakenly thought to be unnecessary. This, however, covers multi-role scenarios where we have already started the controller, which needs to be shut down gracefully if possible if we can't start the worker. A nil check has been added to ensure the panic does not resurface. Co-authored-by: Jeff Mitchell --- CHANGELOG.md | 3 +++ internal/cmd/commands/server/server.go | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1202625ac..62cfa226e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -102,6 +102,9 @@ Canonical reference for changes, improvements, and bugfixes for Boundary. well as the error message) ([issue](https://github.com/hashicorp/boundary/issues/1305), [PR](https://github.com/hashicorp/boundary/pull/1384)) +* server: Fix panic on worker startup failure when the server was not also + configured as a controller + ([PR](https://github.com/hashicorp/boundary/pull/1432)) ### New and Improved diff --git a/internal/cmd/commands/server/server.go b/internal/cmd/commands/server/server.go index f36a01d44..1d48c0f1e 100644 --- a/internal/cmd/commands/server/server.go +++ b/internal/cmd/commands/server/server.go @@ -463,6 +463,11 @@ func (c *Command) Run(args []string) int { if c.Config.Worker != nil { if err := c.StartWorker(); err != nil { c.UI.Error(err.Error()) + if c.controller != nil { + if err := c.controller.Shutdown(false); err != nil { + c.UI.Error(fmt.Errorf("Error with controller shutdown: %w", err).Error()) + } + } return base.CommandCliError } }