Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure postgres is ready to accept connections before neon-proxy starts #4

Merged

Conversation

krachtstefan
Copy link

I found an issue where it is possible to have both containers running without the neon_control_plane schema being created. It's a race condition that is very likely to happen when running docker compose up for the first time.

how to reproduce

  • to be on a clean slate, run docker compose down --volumes to remove the containers and get rid of the db volume
  • run docker-compose up to start everything
  • neon-proxy-1 was not able to create the schema. The logs show that the DB was not initialized at this point even though the Postgres service was started.
...
postgres-1    | creating configuration files ... ok
neon-proxy-1  | psql: error: connection to server at "postgres" (192.168.96.2), port 5432 failed: Connection refused
neon-proxy-1  | 	Is the server running on that host and accepting TCP/IP connections?
...
postgres-1    | PostgreSQL init process complete; ready for start up.
...
  • both containers are running now, but the DB has no neon_control_plane schema
  • press CTRL+C to stop the containers
  • run docker-compose up to start the containers again
  • this time the DB inits faster and it is very likely that the schema will be created

solution

Instead of only waiting for Postgres container to be running, ChatGPT I added a health check that can be used in the depends_on block of the neon-proxy service to guarantee that the DB can be used already.

Now the logs indicate that the DB is used after its initialization.

postgres-1    | PostgreSQL init process complete; ready for start up.
...
neon-proxy-1  | CREATE SCHEMA
...
neon-proxy-1  | CREATE TABLE

…tarts

Signed-off-by: Stefan Kracht <stefankracht@gmail.com>
@TimoWilhelm
Copy link
Owner

Thanks, good catch! I guess I got lucky with the startup so far.

@TimoWilhelm TimoWilhelm merged commit 4ab4ab8 into TimoWilhelm:main May 17, 2024
@krachtstefan
Copy link
Author

You’re welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants