binwiederhier / ntfy

Send push notifications to your phone or desktop using PUT/POST
https://ntfy.sh
Apache License 2.0
18.58k stars 731 forks source link

Segfault on publish (installed with nix) #1025

Closed antony-frolov closed 8 months ago

antony-frolov commented 9 months ago

:lady_beetle: Describe the bug

Got a segfault error when running publish command. Installed ntfy with nix on ubuntu 18.04.

:computer: Components impacted

ntfy server

:bulb: Screenshots and/or logs

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0xc49c93]

goroutine 1 [running]:
heckel.io/ntfy/v2/cmd.defaultClientConfigFileUnix()
    heckel.io/ntfy/v2/cmd/subscribe.go:324 +0x13
heckel.io/ntfy/v2/cmd.defaultClientConfigFile(...)
    heckel.io/ntfy/v2/cmd/subscribe_unix.go:17
heckel.io/ntfy/v2/cmd.loadConfig(0xc0006cb548?)
    heckel.io/ntfy/v2/cmd/subscribe.go:313 +0x30
heckel.io/ntfy/v2/cmd.execPublish(0xc0003eac40)
    heckel.io/ntfy/v2/cmd/publish.go:87 +0x2a
github.com/urfave/cli/v2.(*Command).Run(0x2f3f8e0, 0xc0003eac40, {0xc0003be450, 0x3, 0x3})
    github.com/urfave/cli/v2@v2.25.7/command.go:274 +0x998
github.com/urfave/cli/v2.(*Command).Run(0xc000243600, 0xc0003ea680, {0xc0001d6000, 0x4, 0x4})
    github.com/urfave/cli/v2@v2.25.7/command.go:267 +0xbe5
github.com/urfave/cli/v2.(*App).RunContext(0xc0005da000, {0x290ff78?, 0x2fe5660}, {0xc0001d6000, 0x4, 0x4})
    github.com/urfave/cli/v2@v2.25.7/app.go:332 +0x5b7
github.com/urfave/cli/v2.(*App).Run(...)
    github.com/urfave/cli/v2@v2.25.7/app.go:309
main.main()
    heckel.io/ntfy/v2/main.go:32 +0x31

:crystal_ball: Additional context

pcouy commented 9 months ago

I am having the exact same issue with a docker compose setup. The program counter in the error message differs from the one above, but the call stack is the same.

I'm running ntfy 2.8.0 (aaa4976), runtime go1.21.3, built at 2023-11-19T21:51:43Z

binwiederhier commented 8 months ago

This is wild. The thing that's failing is the user.Current() call, which means that Go cannot determine the current Linux/Windows user. I added logging here https://github.com/binwiederhier/ntfy/commit/ef302d22a981b2fab8b47777b8ebf068507e5091 so we can get an error message, and avoid a panic.

Once I release this (which should be shortly), you can give me more details on the error.

binwiederhier commented 8 months ago

Can you try again with the latest release and give me the error message?

antony-frolov commented 8 months ago

tried the same command with the latest release and it works fine! so the issue is solved for me i guess

binwiederhier commented 8 months ago

Does it print a warning?

antony-frolov commented 8 months ago

it does 2024/03/25 16:37:22 WARN Could not determine default client config file: could not determine current user: user: unknown userid 451693

binwiederhier commented 8 months ago

This fails: https://github.com/binwiederhier/ntfy/blob/main/cmd/subscribe.go#L328-L331

This is a Go standard library call to determine the current user. If this fails, something on your system regarding your current user is unusual or wrong. Check if id, cat /etc/passwd | grep $USER and echo $USER all add up.

antony-frolov commented 8 months ago

there is indeed something unusual, user info on our VMs is stored not in /etc/passwd but in some database common for all VMs i guess. so i can only get my user info with getent passwd $USER

binwiederhier commented 8 months ago

I would have thought that Go does that under the hood :shrug: