Segfault on invalid listen spec
gebn opened this issue · comments
Calling reuseport.Listen()
with a listen spec that lacks a colon causes a segfault. As errors here will usually come from config, it would be good to return invalid listen specs as an error rather than panicking, so it's clear this isn't a bug in the app.
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xa01801]
goroutine 1 [running]:
github.com/kavu/go_reuseport.getTCPSockaddr(0xbb83dd, 0x3, 0x7fffc4746667, 0x5, 0x0, 0x0, 0x0, 0x7f92f89c72e0, 0xc000177cd0)
external/com_github_kavu_go_reuseport/tcp.go:27 +0x61
github.com/kavu/go_reuseport.getSockaddr(0xbb83dd, 0x3, 0x7fffc4746667, 0x5, 0x1000000000000, 0xc8, 0xd8, 0xc0002f8000, 0x0)
external/com_github_kavu_go_reuseport/reuseport.go:30 +0x72
github.com/kavu/go_reuseport.NewReusablePortListener(0xbb83dd, 0x3, 0x7fffc4746667, 0x5, 0x2540be400, 0xd4bf60, 0xc0002e2480, 0x0)
external/com_github_kavu_go_reuseport/tcp.go:103 +0x67
github.com/kavu/go_reuseport.Listen(...)
external/com_github_kavu_go_reuseport/reuseport.go:44
main.reload(0x7fffc4746667, 0x5, 0x7fffc4746653, 0xa, 0xd66580, 0xc0000884c0, 0xc0000a6648)
cmd/x/main.go:131 +0x46e
main.main()
cmd/x/main.go:56 +0x18a
@gebn Hey, George! Thank you for your report. Yes, I definitely need to handle this kind of panic.
But can you help me a little bit here? I just pushed a new version (shame on me for not doing it before) v1.5.0. Can you test your app on it?
Also, can you share an example of your listen spec, that causes a panic? Thanks!
v1.5.0 seems to fix it - a listen spec of 1234
caused a segfault with 1f6171f, but now gives the error address 1234: missing port in address
. Thanks!