From a2a660ed1209528b075a21af84fc0ed3e7b266ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Thu, 10 Feb 2022 17:12:02 +0100 Subject: [PATCH] commands: Fix server deadlock on config error Fixes #9486 --- commands/commandeer.go | 6 ++++++ commands/hugo.go | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/commands/commandeer.go b/commands/commandeer.go index 7706360ab..304ef7a7c 100644 --- a/commands/commandeer.go +++ b/commands/commandeer.go @@ -61,6 +61,8 @@ type commandeer struct { logger loggers.Logger serverConfig *config.Server + buildLock func() (unlock func(), err error) + // Loading state mustHaveConfigFile bool failOnInitErr bool @@ -419,6 +421,10 @@ func (c *commandeer) loadConfig() error { err = createErr } c.hugoSites = h + // TODO(bep) improve. + if c.buildLock == nil { + c.buildLock = h.LockBuild + } close(c.created) }) diff --git a/commands/hugo.go b/commands/hugo.go index b954bf13c..7bfd1443a 100644 --- a/commands/hugo.go +++ b/commands/hugo.go @@ -869,7 +869,7 @@ func (c *commandeer) newWatcher(pollIntervalStr string, dirList ...string) (*wat for { select { case evs := <-watcher.Events: - unlock, err := c.hugo().BaseFs.LockBuild() + unlock, err := c.buildLock() if err != nil { c.logger.Errorln("Failed to acquire a build lock: %s", err) return