Internal server error when pgBouncer fails to connect to the database server
Context
During gitlab#336913 (closed) we provoked a connection failure between pgBouncer and the PostgreSQL server.
Problem
This has generated the following error (Sentry and logs):
unknown: unknown error: scanning repository: failed to connect to `host=pgbouncer-registry.int.gstg.gitlab.net user=gitlab-registry database=gitlabhq_registry`: server error (ERROR: pgbouncer cannot connect to server (SQLSTATE 08P01))
We can see that this was treated as unknown error and therefore led to a 500 Internal Server Error status. Instead, this should have been handled as a persistent database connection error and therefore lead to a 503 Service Unavailable status.