Repository navigation
fix: auto-start hangs in pg_ctl start; reset password for POSTGRES_USER - #57
Open
yashmehrotra wants to merge 3 commits into
Open
yashmehrotra wants to merge 3 commits into
yashmehrotra wants to merge 3 commits into
Conversation
Without -l the daemonised postgres inherits pg_ctl's stdout and holds the pipe open, so the timed pg_ctl run never returns and auto-start hangs on --auto-reset-password and major-version upgrades. Print the server log when start fails or times out so startup errors stay visible.
The env tests cleared PATH for the rest of the package, so tests that need pg_ctl on PATH were silently skipped.
docker-entrypoint.sh runs initdb with POSTGRES_USER, so with a non-default user the "postgres" role does not exist and the password reset fails.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
postgres-cli auto-starthangs forever whenever it starts a temporary server. That happens with--auto-reset-passwordand on major-version upgrades. In Kubernetes thepostgres-upgradeinit container never finishes, so the pod stays atInit:1/2.The last log line is:
Start()runspg_ctl startwithout-l. The background postgres server inherits pg_ctl's stdout and keeps that pipe open.cmd.Wait()therefore never returns. Since clicky v1.21.40 the timeout path also waits forcmd.Wait()after killing pg_ctl, so the CLI blocks forever. Images built against clicky v1.21.1 didn't wait, so the bug was hidden.A second bug sat behind the hang. The entrypoint runs
initdb -U $POSTGRES_USER, but the CLI's username defaults toPG_USERorpostgres. With a non-default user (e.g.POSTGRES_USER=xero), the password reset fails withpq: role "postgres" does not exist.Changes
Start()passes-l $TMPDIR/postgres.logtopg_ctl start, so the server no longer holds the CLI's pipe. When start fails or times out, the server log is printed so startup errors stay visible. Also fixes afmt.Printlnthat printed a literal%w.--usernamefalls back toPG_USER, thenPOSTGRES_USER, thenpostgres, matching the user the entrypoint initialises the cluster with.os.Clearenv(). They were wipingPATHfor the rest of the package, so tests that needpg_ctlskipped silently.Behaviour change
On a successful start, the temporary server's log now goes to
$TMPDIR/postgres.loginstead of the CLI's output. The main server's logging is unchanged: the entrypoint stillexecs postgres directly.Testing
TestStartReturnsWhileServerKeepsRunningrunsinitdbandStart()against a real cluster on a private port and socket dir.Killing processline.TestDefaultUsernamecovers the precedence order.