commands: Fix server deadlock on config error
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 10 Feb 2022 16:12:02 +0000 (17:12 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 10 Feb 2022 18:43:47 +0000 (19:43 +0100)
Fixes #9486

commands/commandeer.go
commands/hugo.go

index 7706360abb01650774f361637b3028b7b4a76ec5..304ef7a7c64f030e62c4d2752a41ec29c2220261 100644 (file)
@@ -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)
        })
 
index b954bf13cbf047d194919ec769ae8687e017a342..7bfd1443aa88682d8227cf0134fffd490be53af5 100644 (file)
@@ -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