Repository: gohugoio/hugo (language: go)

Issue:
`hugo server` stops watching when configuration can't be parsed, but is repaired
### What version of Hugo are you using (`hugo version`)?

<pre>
hugo v0.92.1-85E2E862+extended linux/amd64 BuildDate=2022-01-27T11:44:41Z VendorInfo=gohugoio
</pre>

### Recreate the issue

- have a configuration in subdirectory
- add in `config/_default/params.toml` a section [something.valid]
- add a second identical section [something.valid]
- Hugo prints a warning, but does not indicate failure. (Line "Rebuilt in 55 ms")
- remove the faulty second line
- nothing happens on CLI
- stop Hugo by CTRL+C
- plenty of errors (everything after "Rebuilt in 55 ms")

In my specific case the section was `[dnb.social]` so the errors sound out about social, not somthing.

### Output

```
Change of config file detected, rebuilding site.
2022-02-10 20:21:34.313 +0700
ERROR 2022/02/10 20:21:34 Failed to reload config:

ERROR 2022/02/10 20:21:34 "/home/patrick/github.com/davidsneighbour/kollitsch.de/config/_default/params.toml:1:1": failed to unmarshl config for path "/home/patrick/github.com/davidsneighbour/kollitsch.de/config/_default/params.toml": unmarshal failed: toml: table social already exists
Rebuilt in 55 ms
^C^X
^CFatal Python error: init_import_site: Failed to import the site module
Python runtime state: initialized
Traceback (most recent call last):
  File "/usr/lib/python3.9/site.py", line 606, in <module>
    main()
  File "/usr/lib/python3.9/site.py", line 592, in main
    known_paths = addusersitepackages(known_paths)
  File "/usr/lib/python3.9/site.py", line 322, in addusersitepackages
    addsitedir(user_site, known_paths)
  File "/usr/lib/python3.9/site.py", line 214, in addsitedir
    addpackage(sitedir, name, known_paths)
  File "/usr/lib/python3.9/site.py", line 175, in addpackage
    exec(line)
  File "<string>", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 846, in exec_module
  File "<frozen importlib._bootstrap_external>", line 941, in get_code
  File "<frozen importlib._bootstrap_external>", line 1040, in get_data
KeyboardInterrupt
patrick@main:/dev/pts/0>
[20:29:02][patrick@main]  (+1|%0|!2456|)
```

Also, typo there in `failed to unmarshl config for path`.



Discussion / hints:
Notes:

- The server is not dead, it's "detached". I have to kill it manually via `killall -9 hugo` or the next `hugo server` run will use a different port
- The site is not available via web browser after the "Rebuilt in 55ms"

Fix patch:
diff --git a/commands/commandeer.go b/commands/commandeer.go
index 7706360abb0..304ef7a7c64 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 b954bf13cbf..7bfd1443aa8 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


Test patch: