ntfy icon indicating copy to clipboard operation
ntfy copied to clipboard

Segfault on publish (installed with nix)

Open antony-frolov opened this issue 1 year ago • 1 comments

: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/[email protected]/command.go:274 +0x998
github.com/urfave/cli/v2.(*Command).Run(0xc000243600, 0xc0003ea680, {0xc0001d6000, 0x4, 0x4})
	github.com/urfave/cli/[email protected]/command.go:267 +0xbe5
github.com/urfave/cli/v2.(*App).RunContext(0xc0005da000, {0x290ff78?, 0x2fe5660}, {0xc0001d6000, 0x4, 0x4})
	github.com/urfave/cli/[email protected]/app.go:332 +0x5b7
github.com/urfave/cli/v2.(*App).Run(...)
	github.com/urfave/cli/[email protected]/app.go:309
main.main()
	heckel.io/ntfy/v2/main.go:32 +0x31

:crystal_ball: Additional context

antony-frolov avatar Feb 14 '24 12:02 antony-frolov

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

pcouy avatar Feb 23 '24 08:02 pcouy

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 avatar Mar 07 '24 20:03 binwiederhier

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

binwiederhier avatar Mar 24 '24 18:03 binwiederhier

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

antony-frolov avatar Mar 24 '24 18:03 antony-frolov

Does it print a warning?

binwiederhier avatar Mar 25 '24 13:03 binwiederhier

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

antony-frolov avatar Mar 25 '24 13:03 antony-frolov

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.

binwiederhier avatar Mar 25 '24 13:03 binwiederhier

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

antony-frolov avatar Mar 25 '24 14:03 antony-frolov

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

binwiederhier avatar Mar 25 '24 17:03 binwiederhier