Repository: gohugoio/hugo (language: go)

Issue:
Check potential output format issue with output formats in hugo server on GitHub action
https://discourse.gohugo.io/t/hugo-serve-randomly-fails-to-load-pages-and-alias/44771/8

This isn't obvious to me, but I will try to read through the code to see what may happen. If someone have a project that somehow reproduces this reliably, please shout.


Discussion / hints:
Hey @bep, it took some time but I think I was able to reproduce on a [slimmed and public](https://github.com/jmichelgarcia/docs-temp-2) repository.

**Clean** [build](https://github.com/jmichelgarcia/docs-temp-2/actions/runs/5254069557/jobs/9492217795): 
- 4 pages
- 3 aliases

```
hugo: collected modules in 692 ms
Start building sites … 
hugo v0.113.0+extended linux/amd[6](https://github.com/jmichelgarcia/docs-temp-2/actions/runs/5254069557/jobs/9492217795#step:7:7)4 BuildDate=unknown
WARN 2023/06/13 10:05:5[7](https://github.com/jmichelgarcia/docs-temp-2/actions/runs/5254069557/jobs/9492217795#step:7:8) .File.UniqueID on zero object. Wrap it in if or with: {{ with .File }}{{ .UniqueID }}{{ end }}

                   | EN | FR  
-------------------+----+-----
  Pages            |  4 |  0  
  Paginator pages  |  0 |  0  
  Non-page files   |  0 |  0  
  Static files     | 33 | 33  
  Processed images |  0 |  0  
  Aliases          |  3 |  0  
  Sitemaps         |  0 |  0  
  Cleaned          |  0 |  0  

Total in 11[8](https://github.com/jmichelgarcia/docs-temp-2/actions/runs/5254069557/jobs/9492217795#step:7:9)5 ms
```

**Glitched** [build](https://github.com/jmichelgarcia/docs-temp-2/actions/runs/5254100494/jobs/9492291541)
- 1 page
- no aliases

```
hugo: collected modules in 1259 ms
Start building sites … 
hugo v0.113.0+extended linux/amd[6](https://github.com/jmichelgarcia/docs-temp-2/actions/runs/5254100494/jobs/9492291541#step:7:7)4 BuildDate=unknown

                   | EN | FR  
-------------------+----+-----
  Pages            |  1 |  0  
  Paginator pages  |  0 |  0  
  Non-page files   |  0 |  0  
  Static files     | 33 | 33  
  Processed images |  0 |  0  
  Aliases          |  0 |  0  
  Sitemaps         |  1 |  0  
  Cleaned          |  0 |  0  

Total in 12[9](https://github.com/jmichelgarcia/docs-temp-2/actions/runs/5254100494/jobs/9492291541#step:7:10)3 ms
```
---
I can also **successfully reproduce locally**, by simply executing the below command several times

`hugo --config hugo.toml --configDir config --disableKinds=taxonomy,term,rss,sitemap,robotsTXT --noBuildLock --noChmod --noTimes --watch=false --enableGitInfo=false -e development`


```
docs-temp-2 git:(main) hugo --config hugo.toml --configDir config --disableKinds=taxonomy,term,rss,sitemap,robotsTXT --noBuildLock --noChmod --noTimes --watch=false --enableGitInfo=false -e development
Start building sites … 
hugo v0.113.0+extended darwin/arm64 BuildDate=unknown
WARN 2023/06/13 11:19:15 .File.UniqueID on zero object. Wrap it in if or with: {{ with .File }}{{ .UniqueID }}{{ end }}

                   | EN | FR  
-------------------+----+-----
  Pages            |  4 |  0  
  Paginator pages  |  0 |  0  
  Non-page files   |  0 |  0  
  Static files     | 33 | 33  
  Processed images |  0 |  0  
  Aliases          |  3 |  0  
  Sitemaps         |  0 |  0  
  Cleaned          |  0 |  0  

Total in 410 ms
➜  docs-temp-2 git:(main) hugo --config hugo.toml --configDir config --disableKinds=taxonomy,term,rss,sitemap,robotsTXT --noBuildLock --noChmod --noTimes --watch=false --enableGitInfo=false -e development
Start building sites … 
hugo v0.113.0+extended darwin/arm64 BuildDate=unknown
WARN 2023/06/13 11:19:17 .File.UniqueID on zero object. Wrap it in if or with: {{ with .File }}{{ .UniqueID }}{{ end }}

                   | EN | FR  
-------------------+----+-----
  Pages            |  4 |  0  
  Paginator pages  |  0 |  0  
  Non-page files   |  0 |  0  
  Static files     | 33 | 33  
  Processed images |  0 |  0  
  Aliases          |  3 |  0  
  Sitemaps         |  0 |  0  
  Cleaned          |  0 |  0  

Total in 389 ms
➜  docs-temp-2 git:(main) hugo --config hugo.toml --configDir config --disableKinds=taxonomy,term,rss,sitemap,robotsTXT --noBuildLock --noChmod --noTimes --watch=false --enableGitInfo=false -e development
Start building sites … 
hugo v0.113.0+extended darwin/arm64 BuildDate=unknown

                   | EN | FR  
-------------------+----+-----
  Pages            |  1 |  0  
  Paginator pages  |  0 |  0  
  Non-page files   |  0 |  0  
  Static files     | 33 | 33  
  Processed images |  0 |  0  
  Aliases          |  0 |  0  
  Sitemaps         |  1 |  0  
  Cleaned          |  0 |  0  

Total in 113 ms
```

---

My intuition is telling me that it could be related to my [configs](https://github.com/jmichelgarcia/docs-temp-2/tree/main/config):
- _default
    - hugo.toml
-  production
    - hugo.toml 

When I delete `production/hugo.toml`, then I cannot reproduce this locally anymore. When I add it back, the build randomly glitches.

---

I just did some tests locally (tried to break it starting from 110, and from my tests this glitches was introduced as part of [112](https://github.com/gohugoio/hugo/releases/tag/v0.112.0)

```
hugo v0.112.0-0a95d6704a8ac8d41cc5ca8fffaad8c5c7a3754a+extended darwin/arm64 BuildDate=2023-05-23T08:14:20Z VendorInfo=gohugoio
➜  docs-temp-2 git:(main) ✗ npm run break-it                            

> docs@0.0.1 break-it
> hugo --config hugo.toml --configDir config --disableKinds=taxonomy,term,rss,sitemap,robotsTXT --noBuildLock --noChmod --noTimes --watch=false --enableGitInfo=false -e development --debug

Start building sites … 
hugo v0.112.0-0a95d6704a8ac8d41cc5ca8fffaad8c5c7a3754a+extended darwin/arm64 BuildDate=2023-05-23T08:14:20Z VendorInfo=gohugoio
INFO 2023/06/13 11:46:57 syncing static files to /
INFO 2023/06/13 11:46:57 process in 0 ms
INFO 2023/06/13 11:46:57 assemble in 0 ms
INFO 2023/06/13 11:46:57 render in 2 ms
INFO 2023/06/13 11:46:57 postProcess in 0 ms

                   | EN | FR  
-------------------+----+-----
  Pages            |  1 |  0  
  Paginator pages  |  0 |  0  
  Non-page files   |  0 |  0  
  Static files     | 33 | 33  
  Processed images |  0 |  0  
  Aliases          |  0 |  0  
  Sitemaps         |  1 |  0  
  Cleaned          |  0 |  0  
```
@jmichelgarcia  OK, I can reproduce this too (but very rarely), thanks a lot, much appreciated.
This bash script fails every time:

```bash
#!/bin/bash
for i in {1..100} 
do
    rm -rf public
    hugo --quiet --config hugo.toml --configDir config --disableKinds=taxonomy,term,rss,sitemap,robotsTXT --noBuildLock --noChmod --noTimes --watch=false --enableGitInfo=false -e development
    size=`tree public | wc -l`
    expect=57
    if [ $size -ne $expect ]
    then
        echo "[$i] Expected $expect lines, got $size"
        exit 1
    fi
done
```

Fix patch:
diff --git a/config/allconfig/allconfig.go b/config/allconfig/allconfig.go
index ade9607dded..08792d870d9 100644
--- a/config/allconfig/allconfig.go
+++ b/config/allconfig/allconfig.go
@@ -191,6 +191,22 @@ type configCompiler interface {
 func (c Config) cloneForLang() *Config {
 	x := c
 	x.C = nil
+	copyStringSlice := func(in []string) []string {
+		if in == nil {
+			return nil
+		}
+		out := make([]string, len(in))
+		copy(out, in)
+		return out
+	}
+
+	// Copy all the slices to avoid sharing.
+	x.DisableKinds = copyStringSlice(x.DisableKinds)
+	x.DisableLanguages = copyStringSlice(x.DisableLanguages)
+	x.MainSections = copyStringSlice(x.MainSections)
+	x.IgnoreErrors = copyStringSlice(x.IgnoreErrors)
+	x.IgnoreFiles = copyStringSlice(x.IgnoreFiles)
+	x.Theme = copyStringSlice(x.Theme)
 
 	// Collapse all static dirs to one.
 	x.StaticDir = x.staticDirs()
@@ -787,12 +803,14 @@ func fromLoadConfigResult(fs afero.Fs, logger loggers.Logger, res config.LoadCon
 
 			// Create a copy of the complete config and replace the root keys with the language specific ones.
 			clone := all.cloneForLang()
+
 			if err := decodeConfigFromParams(fs, bcfg, mergedConfig, clone, differentRootKeys); err != nil {
 				return nil, fmt.Errorf("failed to decode config for language %q: %w", k, err)
 			}
 			if err := clone.CompileConfig(logger); err != nil {
 				return nil, err
 			}
+
 			langConfigMap[k] = clone
 		case maps.ParamsMergeStrategy:
 		default:


Test patch:
diff --git a/hugolib/config_test.go b/hugolib/config_test.go
index 7f278f00a8c..5a308720752 100644
--- a/hugolib/config_test.go
+++ b/hugolib/config_test.go
@@ -750,6 +750,74 @@ author: {{ site.Author }}
 
 }
 
+// Issue #11089
+func TestHugoConfigSliceOverrides(t *testing.T) {
+	t.Parallel()
+
+	filesTemplate := `
+-- hugo.toml --
+disableKinds = ["section"]
+[languages]
+[languages.en]
+disableKinds = []
+title = "English"
+weigHt = WEIGHT_EN
+[languages.sv]
+title = "Swedish"
+wEight =  WEIGHT_SV
+disableKinds = ["page"]
+-- layouts/index.html --
+Home: {{ .Lang}}|{{ len site.RegularPages }}|
+-- layouts/_default/single.html --
+Single.
+-- content/p1.en.md --
+-- content/p2.en.md --
+-- content/p1.sv.md --
+-- content/p2.sv.md --
+
+`
+
+	t.Run("En first", func(t *testing.T) {
+		files := strings.ReplaceAll(filesTemplate, "WEIGHT_EN", "1")
+		files = strings.ReplaceAll(files, "WEIGHT_SV", "2")
+
+		cfg := config.New()
+		b, err := NewIntegrationTestBuilder(
+			IntegrationTestConfig{
+				T:           t,
+				TxtarString: files,
+				BaseCfg:     cfg,
+			},
+		).BuildE()
+
+		b.Assert(err, qt.IsNil)
+		b.AssertFileContent("public/index.html", "Home: en|2|")
+		b.AssertFileContent("public/sv/index.html", "Home: sv|0|")
+
+	})
+
+	t.Run("Sv first", func(t *testing.T) {
+		files := strings.ReplaceAll(filesTemplate, "WEIGHT_EN", "2")
+		files = strings.ReplaceAll(files, "WEIGHT_SV", "1")
+
+		for i := 0; i < 20; i++ {
+			cfg := config.New()
+			b, err := NewIntegrationTestBuilder(
+				IntegrationTestConfig{
+					T:           t,
+					TxtarString: files,
+					BaseCfg:     cfg,
+				},
+			).BuildE()
+
+			b.Assert(err, qt.IsNil)
+			b.AssertFileContent("public/index.html", "Home: en|2|")
+			b.AssertFileContent("public/sv/index.html", "Home: sv|0|")
+		}
+	})
+
+}
+
 func TestConfigOutputFormatDefinedInTheme(t *testing.T) {
 	t.Parallel()