Skip to content

Fix login hang when pgtle.clientauth_db_name names a nonexistent database#317

Open
zjyzh wants to merge 1 commit into
aws:mainfrom
zjyzh:fix/clientauth-missing-dbname
Open

Fix login hang when pgtle.clientauth_db_name names a nonexistent database#317
zjyzh wants to merge 1 commit into
aws:mainfrom
zjyzh:fix/clientauth-missing-dbname

Conversation

@zjyzh

@zjyzh zjyzh commented Jul 22, 2026

Copy link
Copy Markdown

Description of the change

Bug

pgtle.clientauth_db_name is PGC_POSTMASTER. If it names a nonexistent (or later-dropped) database, every clientauth worker FATALs and every login hangs on a rendezvous no worker completes. Nobody can log in to fix it.

Root cause

clientauth_hook enqueues and waits on client_cv with no timeout and no check that the shard has a live worker. It can't look up pg_database itself — it runs before InitPostgres.

Fix

Give the hook a way to know whether a worker will ever answer, so it stops waiting forever.

Each background worker now flips a shared "I'm alive" flag once it has successfully attached to the database, and flips it back on exit. When a login arrives, the hook first checks that flag:

  • If no worker comes up within 3 seconds, the hook stops waiting and falls back to the existing behavior — enable_clientauth = 'on' accepts the connection, 'require' rejects it with a clear message saying to check clientauth_db_name.
  • If the worker was alive but dies while handling the request, the hook notices within about a second and takes the same fallback.

The flag is per-worker (not a single "any worker up" bit) because requests are split across workers by client PID, so the hook has to check the specific worker its request will route to.

Branches

aws/pg_tle:mainfix/clientauth-missing-dbname, commit f7588c2.

Testing

Three new TAP subtests in 004_pg_tle_clientauth.pl (#20/#21/#22), all bounded timeout => 15.

Patched: 6/6 pass in ~20s. Unpatched baseline: 77s hang, bails.

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

…base

When clientauth_db_name names a nonexistent (or later-dropped) database,
clientauth workers FATAL at startup and clientauth_hook waits forever on
a rendezvous no worker completes. The GUC is PGC_POSTMASTER, so nobody
can log in to fix it.

Track per-shard worker liveness in shared memory. Workers publish it
after BackgroundWorkerInitializeConnection() and clear it via
before_shmem_exit. clientauth_hook waits 3s for the target shard; on
timeout it falls back to the existing "pg_tle not installed" path
('on' accepts, 'require' FATALs). The post-enqueue client_cv wait is
also bounded and rechecks liveness, so a worker dying mid-request
cannot hang the client either.

Adds TAP subtests aws#20-aws#22 with bounded psql timeouts.
@zjyzh
zjyzh force-pushed the fix/clientauth-missing-dbname branch from f7588c2 to 23e1e46 Compare July 22, 2026 23:42
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.

1 participant