mirror of
https://github.com/gohugoio/hugo.git
synced 2025-03-22 08:32:47 +00:00
Fix leaky goroutine
By making the err chan buffered so both go routines can return. Also make sure that any errors are logged. Fixes #2488
This commit is contained in:
parent
63a6da06d8
commit
a0167d838e
2 changed files with 11 additions and 2 deletions
|
@ -10,6 +10,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
|
"github.com/fortytw2/leaktest"
|
||||||
"github.com/fsnotify/fsnotify"
|
"github.com/fsnotify/fsnotify"
|
||||||
"github.com/spf13/afero"
|
"github.com/spf13/afero"
|
||||||
"github.com/spf13/hugo/helpers"
|
"github.com/spf13/hugo/helpers"
|
||||||
|
@ -185,6 +186,7 @@ func TestMultiSitesBuild(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) {
|
func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) {
|
||||||
|
defer leaktest.Check(t)()
|
||||||
testCommonResetState()
|
testCommonResetState()
|
||||||
siteConfig := testSiteConfig{DefaultContentLanguage: "fr"}
|
siteConfig := testSiteConfig{DefaultContentLanguage: "fr"}
|
||||||
sites := createMultiTestSitesForConfig(t, siteConfig, configTemplate, configSuffix)
|
sites := createMultiTestSitesForConfig(t, siteConfig, configTemplate, configSuffix)
|
||||||
|
@ -347,6 +349,7 @@ func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMultiSitesRebuild(t *testing.T) {
|
func TestMultiSitesRebuild(t *testing.T) {
|
||||||
|
defer leaktest.Check(t)()
|
||||||
testCommonResetState()
|
testCommonResetState()
|
||||||
siteConfig := testSiteConfig{DefaultContentLanguage: "fr"}
|
siteConfig := testSiteConfig{DefaultContentLanguage: "fr"}
|
||||||
sites := createMultiTestSites(t, siteConfig, multiSiteTOMLConfigTemplate)
|
sites := createMultiTestSites(t, siteConfig, multiSiteTOMLConfigTemplate)
|
||||||
|
@ -654,7 +657,6 @@ func TestChangeDefaultLanguage(t *testing.T) {
|
||||||
// Default language is now en, so that should now be the "root" language
|
// Default language is now en, so that should now be the "root" language
|
||||||
assertFileContent(t, "public/fr/sect/doc1/index.html", true, "Single", "Bonjour")
|
assertFileContent(t, "public/fr/sect/doc1/index.html", true, "Single", "Bonjour")
|
||||||
assertFileContent(t, "public/sect/doc2/index.html", true, "Single", "Hello")
|
assertFileContent(t, "public/sect/doc2/index.html", true, "Single", "Hello")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var multiSiteTOMLConfigTemplate = `
|
var multiSiteTOMLConfigTemplate = `
|
||||||
|
|
|
@ -526,7 +526,7 @@ func (s *Site) reBuild(events []fsnotify.Event) (whatChanged, error) {
|
||||||
// We do this in parallel... even though it's likely only one file at a time.
|
// We do this in parallel... even though it's likely only one file at a time.
|
||||||
// We need to process the reading prior to the conversion for each file, but
|
// We need to process the reading prior to the conversion for each file, but
|
||||||
// we can convert one file while another one is still reading.
|
// we can convert one file while another one is still reading.
|
||||||
errs := make(chan error)
|
errs := make(chan error, 2)
|
||||||
readResults := make(chan HandledResult)
|
readResults := make(chan HandledResult)
|
||||||
filechan := make(chan *source.File)
|
filechan := make(chan *source.File)
|
||||||
convertResults := make(chan HandledResult)
|
convertResults := make(chan HandledResult)
|
||||||
|
@ -611,6 +611,13 @@ func (s *Site) reBuild(events []fsnotify.Event) (whatChanged, error) {
|
||||||
|
|
||||||
s.timerStep("read & convert pages from source")
|
s.timerStep("read & convert pages from source")
|
||||||
|
|
||||||
|
for i := 0; i < 2; i++ {
|
||||||
|
err := <-errs
|
||||||
|
if err != nil {
|
||||||
|
jww.ERROR.Println(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
changed := whatChanged{
|
changed := whatChanged{
|
||||||
source: len(sourceChanged) > 0,
|
source: len(sourceChanged) > 0,
|
||||||
other: len(tmplChanged) > 0 || len(i18nChanged) > 0 || len(dataChanged) > 0,
|
other: len(tmplChanged) > 0 || len(i18nChanged) > 0 || len(dataChanged) > 0,
|
||||||
|
|
Loading…
Reference in a new issue