Hugo panic due to missing write permissions on /tmp/hugo_cache

I have two instances of Ubuntu 20.04, one on my desktop PC and one on a server instance:

lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.4 LTS
Release:        20.04
Codename:       focal

On both I installed hugo using the .deb package provided for download. On both systems, install seemed to be successful:

hugo version
hugo v0.92.2-CDF6A0D6+extended linux/amd64 BuildDate=2022-02-11T14:17:39Z VendorInfo=gohugoio

On my desktop PC, I can create and server a new hugo site without problems.

On the server, however, I get a panic when doing so:

hugo new site test
cd test
hugo serve
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x50 pc=0x1612532]

goroutine 1 [running]:
github.com/gohugoio/hugo/hugolib.newHugoSites({{0x25ffb10, 0xc000513b30}, 0xc0001a49c0, 0x0, {0x0, 0x0}, {0x25fb050, 0xc000099310}, {0x0, 0x0, ...}, ...}, ...)
        /root/project/hugo/hugolib/hugo_sites.go:398 +0x832
github.com/gohugoio/hugo/hugolib.NewHugoSites({{0x25ffb10, 0xc000513b30}, 0xc0001a49c0, 0x0, {0x0, 0x0}, {0x25fb050, 0xc000099310}, {0x0, 0x0, ...}, ...})
        /root/project/hugo/hugolib/hugo_sites.go:527 +0x11d
github.com/gohugoio/hugo/commands.(*commandeer).loadConfig.func3()
        /root/project/hugo/commands/commandeer.go:419 +0x4f8
sync.(*Once).doSlow(0xc000099310, 0x21167e0)
        /usr/local/go/src/sync/once.go:68 +0xd2
sync.(*Once).Do(...)
        /usr/local/go/src/sync/once.go:59
github.com/gohugoio/hugo/commands.(*commandeer).loadConfig(0xc00032c0f0)
        /root/project/hugo/commands/commandeer.go:377 +0x8a5
github.com/gohugoio/hugo/commands.newCommandeer(0x1, 0x1, 0x1, 0xc0004e7420, {0x25a9be0, 0xc00036b640}, 0xc00003c5e0, {0x0, 0x0, 0x0})
        /root/project/hugo/commands/commandeer.go:195 +0x310
github.com/gohugoio/hugo/commands.initializeConfig(0x92, 0x48, 0x51, 0x211c0eb, {0x25a9be0, 0xc00036b640}, 0xc0005ffc88)
        /root/project/hugo/commands/hugo.go:125 +0x31
github.com/gohugoio/hugo/commands.(*serverCmd).server(0xc00036b640, 0xc00038e000, {0xc0005ffcf0, 0x0, 0x0})
        /root/project/hugo/commands/server.go:242 +0x1ce
github.com/spf13/cobra.(*Command).execute(0xc00038e000, {0x35fe038, 0x0, 0x0})
        /go/pkg/mod/github.com/spf13/cobra@v1.2.1/command.go:856 +0x60e
github.com/spf13/cobra.(*Command).ExecuteC(0xc000518a00)
        /go/pkg/mod/github.com/spf13/cobra@v1.2.1/command.go:974 +0x3bc
github.com/gohugoio/hugo/commands.Execute({0xc0000b2010, 0x1, 0x1})
        /root/project/hugo/commands/hugo.go:92 +0xb4
main.main()
        /root/project/hugo/main.go:23 +0x58

Any idea what’s going on here and why systems behave differently?

Is it “your” server or are you interchanging a webhost with the term “server” here? Some providers don’t allow running individual instances of programs that listen to a port.

Another thing to check is your Go version on the server. And maybe run hugo server with some more parameters: hugo server --verbose --debug for instance.

Yes, this my server, I set it up from scratch, I’m admin with full root access.
Go version: I had the suspicion that go is interfering, too. I had go 1.17.6 installed (from snap). I meanwhile uninstalled go, to no avail. If I issue hugo server --verbose --debug, the output messages are totally the same.

On your server, can you reproduce the problem with v0.92.1?

Switching to 0.92.1 didn’t change anything.

I could make progress, however: this was/is a permission problem. When issueing hugo only, I get

Error: add site dependencies: create deps: failed to create file caches from configuration: mkdir /tmp/hugo_cache/test: permission denied
Total in 0 ms

I successfully issued sudo hugo server, which created the hugo_cache/test directory. Afterwards, I could run hugo server successfully as regular user.

This brings me to the point: what owner/permissions should the directory /tmp/hugo_cache have?
In my case it was like:

drwxrwxr-x  4 usery usery  4096 Feb 21 15:39 hugo_cache

And I was running hugo serve as userx who was not allowed to create a directory inside hugo_cache. This eventually resulted in a panic.

Thank you for checking. I wanted to make sure this wasn’t anything new.

If userx is not a member of the usery group, the permissions must be 777. In your example, the permissions are 775.

Remove tmp/hugo_cache and set tmp to 0777. That should do the trick on the next hugo run. I wonder why it’s 0775 currently. This might be a configuration issue. Temp folders should be writable by “everyone” and then, if one of those creates a folder that folder can be set to it’s own user rights. So either you ran hugo with usery the first time it ran or something is “different than elsewhere” on your server.

I changed permissions for tmp/hugo_cache to 777, which solved my problem.

Some further thoughts on this:

a) Seems like /tmp/hugo_cache is created by an arbitrary user at first time use. Then permissions depend on the umask of this particular user. Wouldn’t it be better to create this directory at install time, set the owner to root and set the sticky bit for the directory? Like:

drwxrwxrwt  4 root root  4096 Feb 21 15:39 hugo_cache

b) With incorrect access rights in place, I was confronted with a panic and had to investigate the case. I think hugo could/should handle this more gracefully, giving a clear indication what’s wrong here (missing write permissions).

Yes, that’s what I did.

But then it’s a very specific setup you are in, normally test users tend to be in the same user group as your “end”-user. I often just delete the hugo-cache folder so that is not really an issue down the road. I understand the rights set for a certain hugo-user.

Have a look at ways to configure your cache directories if you use Hugo with different users on the same machine (not sure if this includes ANY cache, but I think so):

1 Like

I don’t think this gets enough attention, but setting the HUGO_CACHEDIR to something within each user’s $HOME directory is advantageous for several reasons:

  1. You won’t run into permission problems like this
  2. No collisions if multiple users have the same project name
  3. Persistent storage between restarts (helpful when using Hugo modules)

Actually, it did change something. With v0.92.1 and earlier you get a descriptive error message. With v0.92.2 it panics; this is a regression.

https://github.com/gohugoio/hugo/issues/9539

1 Like

Yes and no.

Yes, you get a descriptive error message if you build the site:

hugo
Error: add site dependencies: create deps: failed to create file caches from configuration: mkdir /tmp/hugo_cache/issue_9539: permission denied
Total in 2 ms

And no, you don’t get a descriptive error message if you preview the site (neither with 0.92.1 nor with 0.92.2):

hugo server
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x50 pc=0x1502a32]

goroutine 1 [running]:
github.com/gohugoio/hugo/hugolib.newHugoSites({{0x23598f0, 0xc0006f63c0}, 0xc00009f280, 0x0, {0x0, 0x0}, {0x23550f0, 0xc0004b5ea0}, {0x0, 0x0, ...}, ...}, ...)
        /root/project/hugo/hugolib/hugo_sites.go:390 +0x832
github.com/gohugoio/hugo/hugolib.NewHugoSites({{0x23598f0, 0xc0006f63c0}, 0xc00009f280, 0x0, {0x0, 0x0}, {0x23550f0, 0xc0004b5ea0}, {0x0, 0x0, ...}, ...})
        /root/project/hugo/hugolib/hugo_sites.go:519 +0x11d
github.com/gohugoio/hugo/commands.(*commandeer).loadConfig.func3()
        /root/project/hugo/commands/commandeer.go:417 +0x4f8
sync.(*Once).doSlow(0xc0004b5ea0, 0x1e77c1f)
        /usr/local/go/src/sync/once.go:68 +0xd2
sync.(*Once).Do(...)
        /usr/local/go/src/sync/once.go:59
github.com/gohugoio/hugo/commands.(*commandeer).loadConfig(0xc0004d77a0)
        /root/project/hugo/commands/commandeer.go:375 +0x8a5
github.com/gohugoio/hugo/commands.newCommandeer(0x1, 0x1, 0x1, 0xc0004d7500, {0x2304e80, 0xc00009e680}, 0xc000084360, {0x0, 0x0, 0x0})
        /root/project/hugo/commands/commandeer.go:193 +0x310
github.com/gohugoio/hugo/commands.initializeConfig(0xf2, 0xca, 0x44, 0x1e7d51f, {0x2304e80, 0xc00009e680}, 0x468c47)
        /root/project/hugo/commands/hugo.go:125 +0x31
github.com/gohugoio/hugo/commands.(*serverCmd).server(0xc00009e680, 0xc000376a00, {0xc0006bfcf0, 0x0, 0x0})
        /root/project/hugo/commands/server.go:242 +0x1ce
github.com/spf13/cobra.(*Command).execute(0xc000376a00, {0x32b1598, 0x0, 0x0})
        /go/pkg/mod/github.com/spf13/cobra@v1.2.1/command.go:856 +0x60e
github.com/spf13/cobra.(*Command).ExecuteC(0xc0006d3400)
        /go/pkg/mod/github.com/spf13/cobra@v1.2.1/command.go:974 +0x3bc
github.com/gohugoio/hugo/commands.Execute({0xc000084030, 0x1, 0x1})
        /root/project/hugo/commands/hugo.go:92 +0xb4
main.main()
        /root/project/hugo/main.go:23 +0x58

This this qualify for another issue in the GitHub repo?

No. This is resolved in the fix for #9539.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.