-
Notifications
You must be signed in to change notification settings - Fork 217
Description
Note: Since I'm already hired to work on GoCommerce this is just a note for me to remember to fix this and how. I'm still open for suggestions on the best fix.
- Do you want to request a feature or report a bug?
Bug
- What is the current behavior?
The gocommerce server will always return an empty reply in single-tenant mode if an SMTP config is missing.
The following panic is logged for any request to the webserver:
2018/10/11 15:33:14 http: panic serving 172.23.0.1:60610: runtime error: invalid memory address or nil pointer dereference
goroutine 1741 [running]:
net/http.(*conn).serve.func1(0xc4205cae60)
/usr/local/go/src/net/http/server.go:1721 +0xd0
panic(0xbfb6c0, 0x129e010)
/usr/local/go/src/runtime/panic.go:489 +0x2cf
context.(*valueCtx).Value(0xc4205d2e10, 0xbe56c0, 0x129ddd0, 0xcd8501, 0x7f311d3c2960)
/usr/local/go/src/context/context.go:478 +0x3f
context.(*valueCtx).Value(0xc4205d2e40, 0xbe56c0, 0x129ddd0, 0xc420039b80, 0x417938)
/usr/local/go/src/context/context.go:478 +0x58
github.com/netlify/gocommerce/vendor/github.com/go-chi/chi.(*Mux).ServeHTTP(0xc420167570, 0x12b9a00, 0xc42028c0e0, 0xc4201ea600)
/go/src/github.com/netlify/gocommerce/vendor/github.com/go-chi/chi/mux.go:67 +0x74
github.com/netlify/gocommerce/api.(*router).ServeHTTP(0xc420597720, 0x12b9a00, 0xc42028c0e0, 0xc4201ea600)
/go/src/github.com/netlify/gocommerce/api/router.go:55 +0x54
github.com/netlify/gocommerce/vendor/github.com/go-chi/chi.ServerBaseContext.func1(0x12b9a00, 0xc42028c0e0, 0xc4201ea500)
/go/src/github.com/netlify/gocommerce/vendor/github.com/go-chi/chi/context.go:126 +0x1de
net/http.HandlerFunc.ServeHTTP(0xc420211d40, 0x12b9a00, 0xc42028c0e0, 0xc4201ea500)
/usr/local/go/src/net/http/server.go:1942 +0x44
github.com/netlify/gocommerce/vendor/github.com/rs/cors.(*Cors).Handler.func1(0x12b9a00, 0xc42028c0e0, 0xc4201ea500)
/go/src/github.com/netlify/gocommerce/vendor/github.com/rs/cors/cors.go:200 +0xe9
net/http.HandlerFunc.ServeHTTP(0xc42059bac0, 0x12b9a00, 0xc42028c0e0, 0xc4201ea500)
/usr/local/go/src/net/http/server.go:1942 +0x44
net/http.serverHandler.ServeHTTP(0xc42032ab00, 0x12b9a00, 0xc42028c0e0, 0xc4201ea500)
/usr/local/go/src/net/http/server.go:2568 +0x92
net/http.(*conn).serve(0xc4205cae60, 0x12ba380, 0xc42014a440)
/usr/local/go/src/net/http/server.go:1825 +0x612
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:2668 +0x2ce
- If the current behavior is a bug, please provide the steps to reproduce.
Create a docker container of gocommerce with the following environment variables:
GOCOMMERCE_OPERATOR_TOKEN: "123456"
GOCOMMERCE_SITE_URL: http://localhost:3000
GOCOMMERCE_API_ENDPOINT: http://localhost:9001
GOCOMMERCE_DB_DRIVER: postgres
GOCOMMERCE_DB_DATABASE_URL: postgres://gocommerce:gocommerce@gocommerce_db?sslmode=disable
GOCOMMERCE_DB_AUTOMIGRATE: 1
GoCommerce will not warn you that the SMTP config if missing when starting up.
When requesting any endpoint on the webserver, an empty reply will be returned and the panic logged.
Why does this happen?
When simply running the container the serve command is run.
It will try to integrate the global SMTP settings into a context object in cmd/serve_cmd.go:35. This does not result in an error and a context is created.
However, because of the missing config, this context has a bad pointer reference. So whenever the HTTP handler tries to access that context it will panic.
- What is the expected behavior?
GoCommerce should fail to start with a missing SMTP config when not started with gocommerce multi.
- Please mention your Go version, and operating system version.
I used the Dockerfile coming with the repo.