consbio / mbtileserver

Basic Go server for mbtiles
ISC License
658 stars 104 forks source link

AutoTLS is not setup correctly #89

Closed kylebarron closed 4 years ago

kylebarron commented 4 years ago

It kept crashing for me while testing out the auto-tls:

> ./go/bin/mbtileserver -d mbtiles/ -p 8000 --enable-reload --tls --domain mydomain.com
HTTPS server started on port 8000
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x8b8736]

goroutine 1 [running]:
main.serve()
    /home/kyle/go/src/github.com/consbio/mbtileserver/main.go:320 +0xd86
main.glob..func1(0x110ffc0, 0xc0000d0510, 0x1, 0x9)
    /home/kyle/go/src/github.com/consbio/mbtileserver/main.go:43 +0x4c
github.com/consbio/mbtileserver/vendor/github.com/spf13/cobra.(*Command).execute(0x110ffc0, 0xc0000200b0, 0x9, 0x9, 0x110ffc0, 0xc0000200b0)
    /home/kyle/go/src/github.com/consbio/mbtileserver/vendor/github.com/spf13/cobra/command.go:766 +0x2aa
github.com/consbio/mbtileserver/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0x110ffc0, 0x0, 0x0, 0x0)
    /home/kyle/go/src/github.com/consbio/mbtileserver/vendor/github.com/spf13/cobra/command.go:852 +0x2ea
github.com/consbio/mbtileserver/vendor/github.com/spf13/cobra.(*Command).Execute(...)
    /home/kyle/go/src/github.com/consbio/mbtileserver/vendor/github.com/spf13/cobra/command.go:800
main.main()
    /home/kyle/go/src/github.com/consbio/mbtileserver/main.go:145 +0x2d
EXITING (abnormal child exit: exit status 2)%                                   kyle at mbtiles-server-test in ~                                         × 4:39
kylebarron commented 4 years ago

For the record I tried the same command on macOS (the original was on Ubuntu 18.04) and got the same crash message.

brendan-ward commented 4 years ago

@kylebarron sorry for the issue - I haven't had a chance to dig in.

Does the same issue present when you omit the --enable-reload option?

kylebarron commented 4 years ago

No rush; I'm not affected by this bug because I'm using Cloudflare for https, but just wanted to let you know.

Yes, it still crashes for me without --enable-reload:

> mbtileserver -d mbtiles/ -p 443 --tls --domain mydomain.com
INFO[0000] Found 43 mbtiles files in mbtiles/

--------------------------------------
Use Ctrl-C to exit the server
--------------------------------------
HTTPS server started on port 443
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x44acb66]

goroutine 1 [running]:
main.serve()
    /Users/kyle/github/go/src/github.com/consbio/mbtileserver/main.go:320 +0xd86
main.glob..func1(0x4baac20, 0xc000324a80, 0x0, 0x7)
    /Users/kyle/github/go/src/github.com/consbio/mbtileserver/main.go:48 +0x62
github.com/consbio/mbtileserver/vendor/github.com/spf13/cobra.(*Command).execute(0x4baac20, 0xc000020110, 0x7, 0x7, 0x4baac20, 0xc000020110)
    /Users/kyle/github/go/src/github.com/consbio/mbtileserver/vendor/github.com/spf13/cobra/command.go:766 +0x2aa
github.com/consbio/mbtileserver/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0x4baac20, 0x0, 0x0, 0x0)
    /Users/kyle/github/go/src/github.com/consbio/mbtileserver/vendor/github.com/spf13/cobra/command.go:852 +0x2ea
github.com/consbio/mbtileserver/vendor/github.com/spf13/cobra.(*Command).Execute(...)
    /Users/kyle/github/go/src/github.com/consbio/mbtileserver/vendor/github.com/spf13/cobra/command.go:800
main.main()
    /Users/kyle/github/go/src/github.com/consbio/mbtileserver/main.go:145 +0x2d
brendan-ward commented 4 years ago

Per changes under #69, we're referencing server.TLSConfig which is not defined. We need to initialize it first:

server.TLSConfig = new(tls.Config)

And also make sure that we're using a TLS enabled net.Listener:

tlsListener := tls.NewListener(listener, server.TLSConfig)
brendan-ward commented 4 years ago

@kylebarron this should now be fixed. I don't have a server handy with a publicly-accessible domain name I'm willing to test on, so feel free to re-open if this breaks for you on your domain name.