sosedoff / pgweb

Cross-platform client for PostgreSQL databases
https://sosedoff.github.io/pgweb
MIT License
8.63k stars 732 forks source link

Pgweb forgets configured url if postgres is down when pgweb starts #404

Closed dimrozakis closed 5 years ago

dimrozakis commented 5 years ago

I have the following snippet in my docker-compose.yml:

  postgresql:
    image: postgres:9-alpine
    volumes:
      - postgres-data:/var/lib/postgresql/data:rw
  pgweb:
    image: sosedoff/pgweb
    environment:
      DATABASE_URL: postgres://postgres:postgres@postgresql:5432/postgres?sslmode=disable
    depends_on:
      - postgresql
    restart: always

When starting up containers with docker-compose up, pgweb will sometimes try to connect to postgresql before it can accept connections. Even with the depends_on, which causes postgresql to be started before pgweb, there's no guarantee it'll be listening when pgweb tries to connect to it. In previous pgweb versions, this would cause the pgweb container to exit and it would get restarted by the configured restart policy.

Recently this behavior has changed. As far as I can tell, if postgresql isn't ready when pgweb tries to connect to it, pgweb won't exit, but it seems to then completely forget the configured DATABASE_URL. Even after postgresql is up and running, when visiting pgweb's web UI, the user is prompted to enter database connection information in order to proceed.

Ideally, I think that pgweb should retry connecting to the configured DATABASE_URL when the user visits the web UI (falling back to requesting connection information if it can't connect to it). Alternatively, reverting to the previous behavior makes it much easier to handle connection errors (by using restart policies in docker/docker-compose, kubernetes, systemd, supervisord or whatever system people are using to run pgweb).

dimrozakis commented 5 years ago

The change in behavior described above was perhaps caused by #399

sosedoff commented 5 years ago

Are you using the latest docker image (sosedoff/pgweb:0.11) ? In any case - i'll have a look.

dimrozakis commented 5 years ago

I'm using sosedoff/pgweb:latest which seems to be pointing to the same image id (81c2f0ef3f5a) as sosedoff/pgweb:0.11.0.

sosedoff commented 5 years ago

I just tried to replicate your issue by having pgweb started using DATABASE_URL env var:

The change you've mentioned (#399) does not make any difference here since it only runs during the start up.

dimrozakis commented 5 years ago

The issue I described occurs if postgres is down when pgweb is starting. So the steps to reproduce would be the following:

sosedoff commented 5 years ago

Oh i see what you mean, i just noticed that when i was running another test.