Skip to content

fix(datastore): do not panic if database credentials are wrong

Jaime Martinez requested to merge 304-fix-db-panic-wrong-creds into master

Log with an error instead of panicking when database credentials are wrong.

Before:

ERRO[0000] connect failed                                database=registry_dev err="failed to connect to `host=localhost user=postgres database=registry_dev`: failed SASL auth (FATAL: password authentication failed for user \"postgres\" (SQLSTATE 28P01))" go_version=go1.16.10 instance_id=35c1b443-5558-48be-990e-441e98ab6c30 version=v3.16.0-gitlab-2-g6e76fb74
panic: failed to construct database connection: failed to connect to `host=localhost user=postgres database=registry_dev`: failed SASL auth (FATAL: password authentication failed for user "postgres" (SQLSTATE 28P01))

goroutine 1 [running]:
github.com/docker/distribution/registry/handlers.NewApp(0x24b7690, 0xc00044b830, 0xc000506000, 0x0)
	/Users/jaime/dev/gitlab/container-registry/registry/handlers/app.go:348 +0x4088
github.com/docker/distribution/registry.NewRegistry(0x24b7690, 0xc00044b830, 0xc000506000, 0x0, 0x0, 0x0)
	/Users/jaime/dev/gitlab/container-registry/registry/registry.go:96 +0x1ab
github.com/docker/distribution/registry.glob..func1(0x2d88220, 0xc0002bb0c0, 0x1, 0x1)
	/Users/jaime/dev/gitlab/container-registry/registry/registry.go:58 +0x189
github.com/spf13/cobra.(*Command).execute(0x2d88220, 0xc0002bb090, 0x1, 0x1, 0x2d88220, 0xc0002bb090)
	/Users/jaime/.asdf/installs/golang/1.16.10/packages/pkg/mod/github.com/spf13/cobra@v1.2.1/command.go:860 +0x2c2
github.com/spf13/cobra.(*Command).ExecuteC(0x2d884a0, 0x0, 0xffffffff, 0xc000190058)
	/Users/jaime/.asdf/installs/golang/1.16.10/packages/pkg/mod/github.com/spf13/cobra@v1.2.1/command.go:974 +0x375
github.com/spf13/cobra.(*Command).Execute(...)
	/Users/jaime/.asdf/installs/golang/1.16.10/packages/pkg/mod/github.com/spf13/cobra@v1.2.1/command.go:902
main.main()
	/Users/jaime/dev/gitlab/container-registry/cmd/registry/main.go:21 +0x2d

After:

ERRO[0000] connect failed                                database=registry_dev err="failed to connect to `host=localhost user=postgres database=registry_dev`: failed SASL auth (FATAL: password authentication failed for user \"postgres\" (SQLSTATE 28P01))" go_version=go1.16.10 instance_id=143b0f66-bee7-4199-bc94-f49346725eff version=v3.16.0-gitlab-2-g6e76fb74.m
FATA[0000] failed to construct database connection: verification failed: failed to connect to `host=localhost user=postgres database=registry_dev`: failed SASL auth (FATAL: password authentication failed for user "postgres" (SQLSTATE 28P01))  go_version=go1.16.10 instance_id=3b229bd0-d294-41e5-93ca-bffc70f269f8 version=v3.17.0-gitlab-2-geadea1df.m

Related to #304 (closed)

Edited by Jaime Martinez

Merge request reports