gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
74.73k stars 7.45k forks source link

hugo --watch update results in an endless loop that consumes 100% CPU #11275

Open CamilleScholtz opened 1 year ago

CamilleScholtz commented 1 year ago
$ hugo version
hugo v0.115.3+extended linux/amd64 BuildDate=unknown

$ uname a
Linux srvpun 5.19.1-0-edge4virt #1-Alpine SMP PREEMPT_DYNAMIC Thu, 11 Aug 2022 14:30:40 +0000 x86_64 GNU/Linux

See the title, a hugo —watch update results in an endless loop that consumes 100% CPU. Running debug it prints the following endlessly:

INFO  Received System Events: [WRITE         "/srv/reactionair.nl/assets/jsconfig.json"]

Change detected, rebuilding site.
2023-07-20 15:59:28.888 +0200
DEBUG Rebuild for events ["WRITE         \"/srv/reactionair.nl/assets/jsconfig.json\""]
DEBUG cachebuster: Matching "assets/jsconfig.json" with source "assets/.*\\.(js|ts|jsx|tsx)": match!
DEBUG cachebuster: Matching "assets/jsconfig.json" with source "assets/.*\\.(css|sass|scss)$": no match
DEBUG cachebuster: Matching "assets/jsconfig.json" with source "(postcss|tailwind)\\.config\\.js": no match
DEBUG cachebuster: Matching "assets/jsconfig.json" with source "assets/.*\\.(.*)$": match!
DEBUG Matching "sass/sass/shop/main.sass" with target "(js|scripts|javascript)": no match
DEBUG Matching "sass/sass/shop/main.sass" with target "json": no match
DEBUG Matching "sass/sass/dark.sass_5c0568ab78ea24c8bd3df4318d414bec" with target "(js|scripts|javascript)": no match
DEBUG Matching "sass/sass/dark.sass_5c0568ab78ea24c8bd3df4318d414bec" with target "json": no match
DEBUG Matching "sass/sass/main.sass" with target "(js|scripts|javascript)": no match
DEBUG Matching "sass/sass/main.sass" with target "json": no match
DEBUG Matching "sass/sass/main.sass_5c0568ab78ea24c8bd3df4318d414bec" with target "(js|scripts|javascript)": no match
DEBUG Matching "sass/sass/main.sass_5c0568ab78ea24c8bd3df4318d414bec" with target "json": no match
DEBUG Matching "webp/images/newsletter/closed.webp" with target "(js|scripts|javascript)": no match
DEBUG Matching "webp/images/newsletter/closed.webp" with target "json": no match
DEBUG Matching "sass/sass/desktop.sass" with target "(js|scripts|javascript)": no match
DEBUG Matching "sass/sass/desktop.sass" with target "json": no match
DEBUG Matching "sass/sass/desktop.sass_5c0568ab78ea24c8bd3df4318d414bec" with target "(js|scripts|javascript)": no match
DEBUG Matching "sass/sass/desktop.sass_5c0568ab78ea24c8bd3df4318d414bec" with target "json": no match
DEBUG Matching "webp/images/newsletter/open.webp" with target "(js|scripts|javascript)": no match
DEBUG Matching "webp/images/newsletter/open.webp" with target "json": no match
DEBUG Matching "sass/sass/shop/mobile.sass" with target "(js|scripts|javascript)": no match
DEBUG Matching "sass/sass/shop/mobile.sass" with target "json": no match
DEBUG Matching "js/js/main.js_f3a8aadac63c177a73ea5bef07d88dec" with target "(js|scripts|javascript)": match!
DEBUG Matching "webp/images/boekencast/de-zahir.webp" with target "(js|scripts|javascript)": no match
DEBUG Matching "webp/images/boekencast/de-zahir.webp" with target "json": no match
DEBUG Matching "sass/sass/shop/main.sass_5c0568ab78ea24c8bd3df4318d414bec" with target "(js|scripts|javascript)": no match
DEBUG Matching "sass/sass/shop/main.sass_5c0568ab78ea24c8bd3df4318d414bec" with target "json": no match
DEBUG Matching "sass/sass/shop/mobile.sass_5c0568ab78ea24c8bd3df4318d414bec" with target "(js|scripts|javascript)": no match
DEBUG Matching "sass/sass/shop/mobile.sass_5c0568ab78ea24c8bd3df4318d414bec" with target "json": no match
DEBUG Matching "sass/sass/light.sass" with target "(js|scripts|javascript)": no match
DEBUG Matching "sass/sass/light.sass" with target "json": no match
DEBUG Matching "sass/sass/dark.sass" with target "(js|scripts|javascript)": no match
DEBUG Matching "sass/sass/dark.sass" with target "json": no match
DEBUG Matching "sass/sass/mobile.sass_5c0568ab78ea24c8bd3df4318d414bec" with target "(js|scripts|javascript)": no match
DEBUG Matching "sass/sass/mobile.sass_5c0568ab78ea24c8bd3df4318d414bec" with target "json": no match
DEBUG Matching "js/js/main.js" with target "(js|scripts|javascript)": match!
DEBUG Matching "sass/sass/shop/desktop.sass" with target "(js|scripts|javascript)": no match
DEBUG Matching "sass/sass/shop/desktop.sass" with target "json": no match
DEBUG Matching "sass/sass/shop/desktop.sass_5c0568ab78ea24c8bd3df4318d414bec" with target "(js|scripts|javascript)": no match
DEBUG Matching "sass/sass/shop/desktop.sass_5c0568ab78ea24c8bd3df4318d414bec" with target "json": no match
DEBUG Matching "sass/sass/light.sass_5c0568ab78ea24c8bd3df4318d414bec" with target "(js|scripts|javascript)": no match
DEBUG Matching "sass/sass/light.sass_5c0568ab78ea24c8bd3df4318d414bec" with target "json": no match
DEBUG Matching "sass/sass/mobile.sass" with target "(js|scripts|javascript)": no match
DEBUG Matching "sass/sass/mobile.sass" with target "json": no match
DEBUG Matching "js/js/shop.js" with target "(js|scripts|javascript)": match!
DEBUG Matching "js/js/shop.js_f3a8aadac63c177a73ea5bef07d88dec" with target "(js|scripts|javascript)": match!
INFO  build: running step process duration 6.283247ms
INFO  build: running step assemble duration 273ns
INFO  build: running step render duration 1.383295608s
INFO  build: running step postProcess duration 137.313µs
Total in 1390 ms
INFO  Received System Events: [WRITE         "/srv/reactionair.nl/assets/jsconfig.json"]

Change detected, rebuilding site.
2023-07-20 15:59:30.389 +0200
DEBUG Rebuild for events ["WRITE         \"/srv/reactionair.nl/assets/jsconfig.json\""]
DEBUG cachebuster: Matching "assets/jsconfig.json" with source "assets/.*\\.(js|ts|jsx|tsx)": match!
...
kurtbruns commented 1 year ago

Ran into the same issue for my site using hugo v0.115.3+extended darwin/arm64 BuildDate=unknown

It appeared to be triggered by VSCode constantly touching the files with a git status -z -uall command. Here is the output from the hugo serve. The rebuild times continue to get longer and longer until the CPU is at %100.

Change detected, rebuilding site.
2023-07-20 10:20:48.595 -0600
WARN  .File.Dir on zero object. Wrap it in if or with: {{ with .File }}{{ .Dir }}{{ end }}
Rebuilt in 663 ms

Change detected, rebuilding site.
2023-07-20 10:20:55.096 -0600
WARN  .File.Dir on zero object. Wrap it in if or with: {{ with .File }}{{ .Dir }}{{ end }}
Rebuilt in 607 ms

Change detected, rebuilding site.
2023-07-20 10:21:01.095 -0600
WARN  .File.Dir on zero object. Wrap it in if or with: {{ with .File }}{{ .Dir }}{{ end }}
Rebuilt in 634 ms

Change detected, rebuilding site.
2023-07-20 10:21:07.095 -0600
WARN  .File.Dir on zero object. Wrap it in if or with: {{ with .File }}{{ .Dir }}{{ end }}
Rebuilt in 631 ms

Change detected, rebuilding site.
2023-07-20 10:21:13.096 -0600
WARN  .File.Dir on zero object. Wrap it in if or with: {{ with .File }}{{ .Dir }}{{ end }}
Rebuilt in 698 ms

Change detected, rebuilding site.
2023-07-20 10:21:19.095 -0600
WARN  .File.Dir on zero object. Wrap it in if or with: {{ with .File }}{{ .Dir }}{{ end }}
Rebuilt in 749 ms

Change detected, rebuilding site.
2023-07-20 10:21:25.095 -0600
WARN  .File.Dir on zero object. Wrap it in if or with: {{ with .File }}{{ .Dir }}{{ end }}
Rebuilt in 788 ms
CamilleScholtz commented 1 year ago

Setting the following setting seems to be a workaround:

[build]
    noJSConfigInAssets = true
bep commented 1 year ago

VSCode constantly touching the files with a git status -z -uall command.

I have never experienced anything like this with VSCode.

If you keep changing a file that Hugo watches, you will get repeated builds. There are ways to get around the described case above, but this also smells like a defect in VSCode.

kurtbruns commented 1 year ago

In my case, I think visual studio code was triggering it when there was a large number of staged files, some of them application generated and not just code or markdown... causing the diff to be extra large. Anyways, outside of VSCode on the command line, it's not an issue and in VSCode as long as I'm not staging a bunch of files, it's also not an issue.

CamilleScholtz commented 1 year ago

For some added context, this is on my VPS, where I am not running an editor such as VSCode. I am running hugo with the flags -w --quiet -s /srv/reactionair.nl and I am running the webserver Caddy, though as far as I know I am not running any kind of file watcher that would interact with or even touch jsconfig.json.